Pages

Thursday 14 November 2013

Difference Between Top-level class and Inner class in Java




Top-level class  

Inner class

It cannot be declared as static.

It can be declared as static.
We cannot use private and protected access modifiers with top-level class
We can use private and protected
access modifiers with inner class as it is the member of the outer class. 
It can be executed independently by the JVM with its class name.
It cannot be executed independently
but can be executed with the the help
of its outer class 
Syntax for .class file -> 
< class_name > . class
Syntax for .class file -> 
< outer_class > $ < inner_class > . class

It cannot have any local top- level class.

We can have local inner class

No comments:

Post a Comment