Write a Java Program to demonstrate use of nested class.

Program Code:
import java.lang.*;
class outer
{
int m=10;
class inner
{
int n=20;
void display()
{
System.out.println("m = "+m);
System.out.println("n = "+n);
}

}
}
class nesteddemo
{
public static void main(String arg[])
{
outer outobj=new outer();
outer.inner inobj=outobj.new inner();
inobj.display();
}
}

Output:
m = 10
n = 20
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: