Java OCA OCP Practice Question 1956

Question

Which statements are true?.

Select the two correct answers.

  • (a) No other static members, except final static fields, can be declared within a non-static member class.
  • (b) If a non-static member class is nested within a class named Outer, methods within the non-static member class must use the prefix Outer.this to access the members of the class Outer.
  • (c) All fields in any nested class must be declared final.
  • (d) Anonymous classes cannot have constructors.
  • (e) If objRef is an instance of any nested class within the class Outer, the expression (objRef instanceof Outer) will evaluate to true.


(a) and (d)

Note

No other static members, except final static fields, can be declared within a non-static member class.

Members in outer instances are directly accessible using simple names (provided they are not hidden).

Fields in nested static member classes need not be final.

Anonymous classes cannot have constructors, since they have no names.

Nested classes define distinct types from the enclosing class, and the instanceof operator does not take the type of the outer instance into consideration.




PreviousNext

Related