- Home/
- GATE MECHANICAL/
- GATE ME/
- Article
Which statement is true about a static nested class?
By BYJU'S Exam Prep
Updated on: September 25th, 2023
Which statement is true about a static nested class?
- You must have a reference to an instance of the enclosing class in order to instantiate it.
- Its variables and methods must be static.
- It must extend the enclosing class.
- It does not have access to non-static members of the enclosing class.
Table of content
Answer: D. It does not have access to non-static members of the enclosing class.
A static nested class does not have access to non-static members of the enclosing class.
Solution
Option A is wrong since a reference to an instance of the enclosing class is not required of static nested classes (hence cannot be used by them).
Option B is incorrect because a nested or inner class need not extend anything by default.
Option C is wrong since static nested classes can declare and define non-static members.
A static nested class cannot access the non-static members of the class because it is not connected to an instance of the enclosing class, just like a static method. Therefore, the answer to the question- Which statement is true about a static nested class is option D.
☛ Related Questions: