Difference between Java inner class and static nested class

Submitted 3 years, 5 months ago
Ticket #293
Views 256
Language/Framework Java
Priority Low
Status Closed

What are the main difference between an inner class and a static nested class in Java? Is it play a role in choosing  design / implementation ?

Submitted on Nov 16, 20
add a comment

1 Answer

Verified

 INNER CLASS :

1)Without an outer class object existing, there cannot be an inner class object. That is, the inner class object is always associated with the outer class object.

2) Inside normal/regular inner class, static members can’t be declared.

3) As main() method can’t be declared, regular inner class can’t be invoked directly from the command prompt.

4) Both static and non static members of outer class can be accessed directly.

STATIC NESTED CLASS:

1)Without an outer class object existing, there may be a static nested class object. That is, static nested class object is not associated with the outer class object.

2) Inside static nested class, static members can be declared.

3) As main() method can be declared, the static nested class can be invoked directly from the command prompt.

4) Only a static member of outer class can be accessed directly.

Submitted 3 years, 5 months ago


Latest Blogs