0% found this document useful (0 votes)
6 views

Program 8

Uploaded by

zaheerone86
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Program 8

Uploaded by

zaheerone86
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

OOP WITH JAVA

PROGRAM 8 : 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.

Open notepad and write a program then save it by name


OuterInnerDemo.java Command :
Javac OuterInnerDemo.java
Java OuterInnerDemo

import java.util.Scanner;

// Outer class definition


class Outer {
public void display(String outerValue) {
System.out.println("Display method of Outer class: " + outerValue);
}

// Inner class definition inside Outer class


class Inner {
public void display(String innerValue) {
System.out.println("Display method of Inner class: " " + innerValue);
}
}
}
public class OuterInnerDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.print("Enter a value for the Outer class: ");


String outerInput = sc.nextLine();

System.out.print("Enter a value for the Inner class: ");


String innerInput = sc.nextLine();

Outer outerObject = new Outer();

outerObject.display(outerInput);

Outer.Inner innerObject = outerObject.new Inner();


innerObject.display(innerInput);
sc.close();
}
}

Dept of CSE & ISE SDIT, Kenjar Mr. ABHISHEK M GOWDA

You might also like