Skip to content

Commit f0576ec

Browse files
main
1 parent 1b3538a commit f0576ec

File tree

11 files changed

+229
-3
lines changed

11 files changed

+229
-3
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package Instance.InstanceBlock;
2+
3+
public class program2 {
4+
5+
int x =90;
6+
7+
{
8+
System.out.println(x);
9+
}
10+
11+
12+
void fun(){
13+
System.out.println("In fun");
14+
}
15+
16+
public static void main(String[] args) {
17+
program2 obj = new program2();
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Instance.InstanceBlock;
2+
3+
public class program3 {
4+
5+
int x = 10;
6+
7+
{
8+
System.out.println("instatnce block");
9+
}
10+
11+
program3(){
12+
13+
System.out.println(x);
14+
System.out.println("In constructor..!");
15+
}
16+
17+
public static void main(String[] args) {
18+
19+
program3 obj = new program3();
20+
21+
}
22+
23+
{
24+
System.out.println("Second instance block");
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
package Static.StaticBlock;
3+
4+
public class program8 {
5+
6+
static {
7+
// a= 90;
8+
System.out.println(a);
9+
}
10+
public static void main(String[] args) {
11+
System.out.println(a);
12+
}
13+
14+
static int a =20;
15+
}

12.Inheritance/InstanceInParent/InheritanceClassCodes/program4.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void access(){
1414

1515
class child4 extends Parent4{
1616
int y = 20;
17+
int x =90;
1718
child4(){
1819

1920
System.out.println("In child Constructor");
@@ -27,6 +28,7 @@ class client4{
2728
public static void main(String[] args) {
2829
child4 obj = new child4();
2930
obj.access();
31+
3032

3133
}
3234
}

12.Inheritance/StaticInParent/program6.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ void access(){
4949

5050
class client6{
5151
public static void main(String[] args) {
52-
child6 obj = new child6();
53-
52+
Parent6 obj = new child6();
53+
System.out.println(obj.x);
54+
System.out.println(obj.y);
5455
// obj.access();
5556
}
5657
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package MethodOverriding;
2+
3+
class Parent28{
4+
int x =10;
5+
6+
static int y =20;
7+
8+
}
9+
10+
class Child28 extends Parent28{
11+
12+
int x =90;
13+
14+
static int y =30;
15+
}
16+
17+
class Client28{
18+
19+
public static void main(String[] args) {
20+
Parent28 obj = new Child28();
21+
System.out.println(obj.x);
22+
System.out.println(obj.y);
23+
24+
}
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package AnnonymousIC.Normal;
2+
3+
4+
class Demo2{
5+
6+
int x =10;
7+
8+
void marry(){
9+
10+
System.out.println("Kriti Sanon");
11+
}
12+
}
13+
14+
15+
class Client2{
16+
17+
public static void main(String[] args) {
18+
19+
Demo2 obj = new Demo2(){ // Demo2 obj = new Client2$1(); // Internally
20+
int x =20;
21+
private int y =20;
22+
23+
void marry(){
24+
System.out.println("Nupoor Sanon");
25+
}
26+
27+
Demo2 fun(){
28+
System.out.println("In fun");
29+
return new Demo2();
30+
}
31+
32+
}.fun();
33+
34+
obj.marry();
35+
36+
System.out.println(obj.x);
37+
38+
39+
}
40+
41+
}

15.InnerClass/NormalIC/10_normal.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package NormalIC;
2+
3+
class Outer10{
4+
5+
int z =20;
6+
static int x =10;
7+
8+
class Inner10{
9+
10+
int z =30;
11+
static int y =90; // In version 8 - 11 not allowed
12+
13+
14+
void fun(){
15+
System.out.println(z);
16+
}
17+
}
18+
}
19+
20+
class Client10{
21+
22+
public static void main(String[] args) {
23+
24+
Outer10 obj1 = new Outer10();
25+
26+
System.out.println(obj1.new Inner10().y); // to fill the constructor with this and this$0 of inner class
27+
28+
Outer10.Inner10 obj = new Outer10().new Inner10();
29+
System.out.println(obj.y);
30+
31+
System.out.println(Outer10.Inner10.y);
32+
}
33+
}

15.InnerClass/NormalIC/7_Normal.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,30 @@
22

33
class Outer7{
44

5+
private int x =10;
6+
7+
Outer7(){
8+
9+
}
10+
11+
12+
513
class Inner7{
614

15+
int x =90;
16+
17+
18+
Inner7(int x){
19+
System.out.println(x);
20+
}
21+
22+
Inner7(){
23+
System.out.println("Inner this reference: "+this);
24+
System.out.println("Outer this reference: "+Outer7.this);
25+
System.out.println("Outer class variable: "+Outer7.this.x);
26+
System.out.println(x);
27+
}
28+
729
void fun2(){
830

931
System.out.println("Inner fun");
@@ -19,7 +41,12 @@ void fun1(){
1941
class client7{
2042

2143
public static void main(String[] args) {
22-
Outer7.Inner7 obj = new Outer7().new Inner7();
44+
45+
Outer7 obj1 = new Outer7();
46+
System.out.println("Outer obj: "+obj1);
47+
Outer7.Inner7 obj =obj1.new Inner7();
48+
49+
System.out.println("Inner obj: "+obj);
2350

2451
}
2552
}

15.InnerClass/NormalIC/8_normal.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package NormalIC;
2+
3+
class Outer8{
4+
5+
class Inner8{
6+
7+
class Innerin8{
8+
9+
}
10+
}
11+
}
12+
13+
class client8{
14+
public static void main(String[] args) {
15+
Outer8.Inner8.Innerin8 obj = new Outer8().new Inner8().new Innerin8();
16+
}
17+
}

15.InnerClass/NormalIC/9_normal.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package NormalIC;
2+
3+
class Outer9{
4+
5+
int x = 10;
6+
int y = 20;
7+
8+
void m1(){
9+
10+
int a =30;
11+
// static int b =30; Error
12+
// final static int b =30; Error
13+
}
14+
15+
public static void main(String[] args) {
16+
int p = 50;
17+
// static int q = 60; Error
18+
19+
}
20+
}

0 commit comments

Comments
 (0)