0% found this document useful (0 votes)
5 views2 pages

Java Outer and Inner Class Example

The document describes a Java program that demonstrates the concept of nested classes. It features an outer class named 'Outer' with a display method and an inner class named 'Inner' with its own display method. The main class, 'OuterInnerDemo', creates instances of both classes and calls their display methods, producing output that confirms their functionality.

Uploaded by

punithkumar093k
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Outer and Inner Class Example

The document describes a Java program that demonstrates the concept of nested classes. It features an outer class named 'Outer' with a display method and an inner class named 'Inner' with its own display method. The main class, 'OuterInnerDemo', creates instances of both classes and calls their display methods, producing output that confirms their functionality.

Uploaded by

punithkumar093k
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like