hamburger

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?

  1. You must have a reference to an instance of the enclosing class in order to instantiate it.
  2. Its variables and methods must be static.
  3. It must extend the enclosing class.
  4. It does not have access to non-static members of the enclosing class.

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:

GATE ME

Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium