Java Programming - Inner Classes - Discussion
Discussion Forum : Inner Classes - General Questions (Q.No. 4)
4.
Which statement is true about a static nested class?
Answer: Option
Explanation:
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.
Discussion:
3 comments Page 1 of 1.
Yogesh Killedar said:
6 years ago
Option B is Wrong because a nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class.
(1)
Ravi said:
10 years ago
Static class can access to non static member of enclosing class through an object. So the option B is wrong.
Purnima said:
8 years ago
Even C option is also correct, why because its variables and methods must be static.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers