-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinnerclass.java
More file actions
84 lines (67 loc) · 1.69 KB
/
Copy pathinnerclass.java
File metadata and controls
84 lines (67 loc) · 1.69 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class A
{
int age = 10;
public void showA()
{
System.out.println("show of A");
}
class B
{
public void showB()
{
System.out.println("show of B");
}
}
static class C
{
public void showC()
{
System.out.println("show of C");
}
}
}
abstract class D
{
public abstract void showD();
public abstract void confD();
}
public class innerclass {
public static void main(String[] args) {
// anonymous inner class - creating A class object and providing specific methods to override
A obj = new A()
{
public void showA()
{
System.out.println("show A in main method");
}
};
System.out.println(obj.age);
obj.showA();
System.out.println();
// directly calling class B obj error
// B obj1 = new B();
// obj1.showB();
System.out.println();
// creating B object using A.B reference
A.B obj2 = obj.new B();
obj2.showB();
// creating C object directly without A class object because static class c
A.C obj3 = new A.C();
obj3.showC();
System.out.println();
// abstract anonymous inner class - works because obj4 is obj of inner class and not of abstract class D
D obj4 = new D()
{
public void showD()
{
System.out.println("show of D");
}
public void confD()
{
System.out.println("conf of D");
}
};
obj4.showD();
obj4.confD();
}
}