This is a Java Program to Illustrates Use of Referencing the Object from Inner Class.
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;
void test1()
{
System.out.println("Success");
}
static public class InnerClass
{
private String name = "Peakit";
public void test2()
{
Outer_Class outer = new Outer_Class();
outer.test1();
}
}
public static void main(String[] args)
{
obj = new Outer_Class.InnerClass();
obj.test2();
}
}
Output:
$ javac Outer_Class.java $ java Outer_Class Success
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Check Java Books
- Check Programming Books
- Practice BCA MCQs
- Practice Information Technology MCQs
- Apply for Java Internship