Java OCA OCP Practice Question 1813

Question

Which statements are true?.

Select the two correct answers.

  • (a) A class can only be extended by one class.
  • (b) Every Java object has a public method named equals.
  • (c) Every Java object has a public method named length.
  • (d) A class can extend any number of classes.
  • (e) A non-final class can be extended by any number of classes.


(b) and (e)

Note

The Object class has a public method named equals, but it does not have any method named length.

Since all classes are subclasses of the Object class, they all inherit the equals() method.

Thus, all Java objects have a public method named equals.

In Java, a class can only extend a single superclass, but there is no limit on how many classes can extend a superclass.




PreviousNext

Related