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
Post A Comment:
0 comments: