Non-static nested classes are slightly different from static nested classes, a non-static nested class is actually associated to an object rather than to the class in which it is nested.
Any member of the inner nested class is not a part of its outer class while its source code is in the class definition. Non-static members of a class specify the requirements of objects created from that class. Every object has a copy of the nested class that belongs to the outer class. The same copy should access all the methods and instance variables of that object.
Methods and variables of an inner class can be access directly by the object of outer class. The figure given below illustrates it logically.
Lets try to explain the concept of inner nested class with the help of an example. There is an inner class company exists within an outer class Info. The class Info is to be referred as non-static nested class. The class Info invokes the method of the class Company with the help of the object of the class Company.
Here is the code of the Example :
Here is the output of the Example :
Our Company Name : Rose India
The time of the company : 10
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.