Java OCA OCP Practice Question 1608

Question

Which of the following statements are true?

Select 2 options

  • A. method length () of String class is a final method.
  • B. You can make mutable subclasses of the String class.
  • C. StringBuilder extends String.
  • D. StringBuilder is a final class.
  • E. String class is not final.


Correct Options are  : A D

Note

For A.

Actually, String class itself is final and so all of its methods are implicitly final.

For B.

Both String and StringBuilder are final classes. So is StringBuffer.

For C.

StringBuilder extends Object

For D.

String, StringBuilder, and StringBuffer - all are final classes.

The wrapper classes (java.lang.Boolean, java.lang.Integer, java.lang.Long, java.lang.Short etc.) are final and so they cannot be extended.

java.lang.Number, however, is not final. Integer, Long, Double etc. extend Number.

java.lang.System is final as well.




PreviousNext

Related