Java OCA OCP Practice Question 417

Question

Which of these statements are true?

Select 2 options

  • A. A super () or this () call must be provided as the first statement in the body of the constructor.
  • B. If a subclass does not have any declared constructors, the implicit default constructor of the subclass will have a call to super ().
  • C. If neither super () or this () is declared as the first statement of the body of a constructor, then this () will implicitly be inserted as the first statement.
  • D. super (...) can only be called in the first line of the constructor but this (...) can be called from anywhere.
  • E. You can either call super (...) or this (...) but not both.


Correct Options are  : B E

Note

A. is wrong answer.

super () is automatically added if the sub class constructor doesn't call any of the super class's constructor.

Calling super () will not always work.

If the super class has defined a constructor with arguments and has not defined a no args constructor then no args constructor will not be provided by the compiler.

It is provided only to the class that does not define any constructor explicitly.




PreviousNext

Related