Normal / Regular Inner class

 Normal/ Regular Inner class

=====================================

If we are declaring any named class directly inside a class without static  modifier, such type of inner class is called Normal or Regular inner class.

 Ex 1.

 

 

Ex 2.

Inside inner class we cannot declare any static member. Hence we cannot declare main method and we can't run inner class directly from command prompt.
Ex.


 Case 1. Accessing inner class code from static area of outer class.

 

Case 2. Accessing inner class code from instance area of Outer class.


 Case 3. Accessing inner class code from outside of Outer class.

 

 


For normal or regular inner class we can access both static or non static members of outer class directly.

 

 

Note:

  • Within the inner class 'this' always refers current inner class object. 

  • If we want to refer  current outer class object, we have to use OuterClassName.this

 

 

  • The only applicable modifiers for Outer classes are- 

 

  • But for inner classes applicable modifiers are- 

 

 

Nesting of Inner class

=============================================

Inside inner class we can declare another inner class. Mean nesting of inner class in possible. 

 

 

Related topic

  1. Inner class
  2. Normal / Regular inner class.
  3. Method local inner class.
  4. Anonymous inner class.
  5. Static nested class.
 
 
RAKESH RAKA

I am Rakesh Raka, senior software engineer (JAVA) in Sopra Steria.

Post a Comment (0)
Previous Post Next Post