forked from Nabin-joshi/java_notes_and_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InnerClass.java
58 lines (43 loc) · 1.18 KB
/
InnerClass.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class I{
int age;
public void show(){
System.out.println("Hello");
}
class N{
public void config(){
System.out.println("Config");
}
}
static class c{
public void cshow(){
System.out.println("hello");
}
}
public void showString(){
System.out.println("hello from local inner class");
class localInnerClass{
void print(){
System.out.println("print");
}
}
// localInnerClass localInnerClass = new localInnerClass();
// localInnerClass.print();
}
}
public class InnerClass {
public static void main(String[] args) {
I i = new I();
i.show();
//inner class is the concept of class inside the class
//if we want to access the method of inner class we have to specify
//that the class belongs to I and call it's method
//or we can make it static so that we can call it by class name
I.N obj = i.new N();
obj.config();
//calling static inner class
//static class is not available for non inner class
I.c ob = new I.c();
ob.cshow();
i.showString();
}
}