Write a program in Java to demonstrate inner class.
import java.util.*;
class outer {
int x;
void show () {
Inner I1=new Inner();
I1.get();
I1.put();
}
class Inner {
int y;
void get() {
Scanner in = new Scanner(System.in);
System.out.println("\n enter value for x & y");
x=in.nextInt();
y=in.nextInt();
}
void put() {
System.out.println("\n value for x is " +x);
System.out.println("\n value for y is "+y);
}
}
}
class Inner {
public static void main(String[] arg) {
outer ol=new outer();
ol.show();
}
}
Output
enter value for x & y :20 40 value for x is 20 value for y is 40
0 Comments