Java OCA OCP Practice Question 2509

Question

What statements are true about the following code? (Choose all that apply.)

public class Shape {} 
public class Animal { 
  public String name; 
} 
public class Fish extends Animal { 
  public Shape tail; 
} 
public class Whale extends Fish {} 
  • A. Whale has-a name.
  • B. Whale has-a Shape.
  • C. Whale is-a Shape.
  • D. Whale is-a Animal.
  • E. Fish is-a Whale.
  • F. Animal has-a Shape.


A, B, D.

Note

A is correct because name is public and therefore inherited by the Whale class.

B is correct because Whale is-a Fish and Fish has-a Shape; therefore, since tail is public, it is inherited and Whale has-a Shape.

C is incorrect, because Whale is not inherited from Shape.

D is correct, because Whale is-a Fish and Fish is-a Animal; therefore, Whale is-a Animal.

E is incorrect, because the relationship is reversed.

F is incorrect, since Animal does not have a Shape attribute.




PreviousNext

Related