-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInnerClass.java
More file actions
42 lines (34 loc) · 892 Bytes
/
InnerClass.java
File metadata and controls
42 lines (34 loc) · 892 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
class A {
int age;
public void show() {
System.out.println("in a show");
}
// we can also make this class static
static class B {
int age;
public void config() {
System.out.println("in b config");
}
}
}
public class InnerClass {
public static void main(String args[]) {
// how to call config
A obj = new A();
obj.show();
A.B obj1 = new A.B();
// creating object of b with object of a
// A.B obj1 = obj.new B();
// obj1.config();
// when b is static class
A.B obj2 = new A.B();
obj2.config();
// anonymous inner class
A obj3 = new A() {
public void show() {
System.out.println("in new Show");
}
};
obj3.show();
}
}