Skip to content

Commit 7d451be

Browse files
committed
Inner Class Codes (Normal and Anonymous)
1 parent 87463d5 commit 7d451be

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

InnerClasses/10_NormalInnerClass.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Outer {
2+
3+
int x = 10;
4+
static int y = 20;
5+
class Inner {
6+
7+
void m1() {
8+
9+
System.out.println("Method-1-Inner");
10+
System.out.println(x);
11+
System.out.println(y);
12+
m2();
13+
}
14+
}
15+
void m2() {
16+
17+
System.out.println("Method-2-Outer");
18+
}
19+
}
20+
class Clinet {
21+
22+
public static void main(String[] args) {
23+
24+
Outer obj = new Outer();
25+
26+
Outer.Inner obj1 = obj.new Inner();
27+
obj1.m1();
28+
}
29+
}

InnerClasses/11_NormalInnerClass.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Outer {
2+
3+
int x = 10;
4+
static int y = 20;
5+
6+
class Inner {
7+
8+
int a = 30;
9+
static int b = 40;
10+
void m1() {
11+
12+
System.out.println(a);
13+
System.out.println(b);
14+
}
15+
}
16+
}
17+
class Main {
18+
19+
public static void main(String[] args) {
20+
21+
System.out.println(Outer.Inner.b);
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Demo {
2+
3+
void marry() {
4+
5+
System.out.println("Kriti Sanon");
6+
}
7+
}
8+
class Main {
9+
10+
public static void main(String[] args) {
11+
12+
Demo obj = new Demo() {
13+
14+
void marry() {
15+
16+
System.out.println("Disha Patni");
17+
}
18+
};
19+
obj.marry();
20+
}
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Demo {
2+
3+
void marry() {
4+
5+
System.out.println("Kriti Sanon");
6+
}
7+
}
8+
9+
class Main {
10+
11+
public static void main(String[] args) {
12+
13+
Demo obj = new Demo() {
14+
15+
void marry() {
16+
17+
System.out.println("Disha patni");
18+
//fun();
19+
}
20+
Demo fun() {
21+
22+
System.out.println("Fun-Method");
23+
return new Demo();
24+
}
25+
}.fun();
26+
obj.marry();
27+
}
28+
}
29+

0 commit comments

Comments
 (0)