It is possible to define a class within another class, such classes are known as nested classes. The most important type of nested class is the inner class. An inner class is a non-static nested class. It has access to all of the variables and methods of its outer class and may refer to them directly in the same way that other non-static members of the outer class do.
Here is the source code of the Java Program to Illustrates Use of Referencing the Object from Inner Class. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Outer_Class
static Outer_Class.InnerClass obj;
static public class InnerClass
private String name = "Peakit";
public void test2()
Outer_Class outer = new Outer_Class();
public static void main(String args)
obj = new Outer_Class.InnerClass();
$ javac Outer_Class.java $ java Outer_Class Success
Sanfoundry Global Education & Learning Series – 1000 Java Programs.