-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19_NestedClass.java
More file actions
43 lines (39 loc) · 956 Bytes
/
19_NestedClass.java
File metadata and controls
43 lines (39 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Program of Nested Class
*/
package javaprograms;
/**
*
* @author Geeky Keshav
*/
public class NestedClass
{
static String name="Geeky"; //Variable must be assigned as 'static'
/*void displ()
{
System.out.println("Hello");
}*/
static class name1
{
void msg()
{
System.out.println("Data is: "+name);
}
void disp()
{
name1 obj1=new name1();
obj1.msg();
//obj1.displ(); //Cannot call outer class method in inner class
}
public static void main(String args[])
{
name1 obj=new name1();
//NestedClass obj=new NestedClass(); // Cannot Create object using outer class in inner class
obj.disp();
//obj.displ(); // Cannot connect to outer class method
}
}
}
/*****OUTPUT*****
* Data is: Geeky
*/