How to create object of the inner class?

How to create object of the inner class?
A. OuterClass.InnerClass innerObject = outerObject.new InnerClass();
B. OuterClass.InnerClass innerObject = new InnerClass();
C. InnerClass innerObject = outerObject.new InnerClass();
D. OuterClass.InnerClass = outerObject.new InnerClass();
 
Answer: a
Explanation: An instance of inner class can exist only within instance of outer class. To instantiate the inner class, one must instantiate the outer class first. This can be done by the correct syntax above.
 

Tìm kiếm

Back
Top