Inner Classes

Q1: Which statement is true about a static nested class?

A It must extend the enclosing class.

B You must have a reference to an instance of the enclosing class in order to instantiate it.

C It's variables and methods must be static.

D It does not have access to nonstatic members of the enclosing class.

ANS:B - It does not have access to nonstatic members of the enclosing class.

Option B is correct because a static nested class is not tied to an instance of the enclosing class, and thus can't access the nonstatic members of the class (just as a static method can't access nonstatic members of a class). Option A is incorrect because static nested classes do not need (and can't use) a reference to an instance of the enclosing class. Option C is incorrect because static nested classes can declare and define nonstatic members. Option D is wrong because it just is. There's no rule that says an inner or nested class has to extend anything.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.