Program 08 : Outer class
Develop a JAVA program to create an outer class with a function display. Create another class inside
the outer class named inner with a function called display and call the two functions in the main class.
Java Code
class Outer {
void display() {
[Link]("Outer class display method");
class Inner {
void display() {
[Link]("Inner class display method");
public class OuterInnerDemo {
public static void main(String[] args) {
// Create an object of the Outer class
Outer outerObj = new Outer();
// Call the display method of the Outer class
[Link]();
// Create an object of the Inner class using outer object
[Link] innerObj = [Link] Inner();
// Call the display method of the Inner class
[Link]();
In this program, the Outer class has a method named display, and it also contains an inner class
named Inner with its own display method. In the main method of the OuterInnerDemo class, an
instance of the outer class (Outer) is created, and its display method is called. Then, an instance of the
inner class (Inner) is created using the outer class instance, and its display method is called. This
demonstrates the concept of nesting classes in Java.
Output
$ java OuterInnerDemo
Outer class display method
Inner class display method