Skip to content

Commit 3fdcd04

Browse files
OOP
1 parent c780e9c commit 3fdcd04

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

11.Classes&Objects/Instance/Constructor/program9.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ class demo3{
66

77
void fun(){
88
String str2 = "Shashi";
9+
// System.out.println(System.identityHashCode(str2));
910
String str3 = new String("Core2Web");
1011
}
1112

1213
public static void main(String[] args) {
1314
demo3 obj = new demo3();
15+
// System.out.println(System.identityHashCode(obj.str1));
1416

1517
obj.fun();
1618
}

11.Classes&Objects/Instance/InstanceBlock/program3.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
public class program3 {
44

5-
int x = 10;
5+
static int x;
6+
7+
static{
8+
System.out.println("In static block 1"+x);
9+
}
610

711
{
812
System.out.println("instatnce block");
@@ -16,8 +20,14 @@ public class program3 {
1620

1721
public static void main(String[] args) {
1822

19-
program3 obj = new program3();
23+
// program3 obj = new program3();
24+
x = 10;
25+
26+
27+
}
2028

29+
static{
30+
System.out.println("In static block 2"+x);
2131
}
2232

2333
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package OOP_ClassCodes;
2+
3+
class Demo1{
4+
5+
static int x = 10;
6+
int y = 20;
7+
8+
static {
9+
int a = 10;
10+
System.out.println(a);
11+
System.out.println("In Static block I");
12+
System.out.println(p);
13+
}
14+
15+
{
16+
System.out.println("In Instance block I ");
17+
}
18+
19+
public static void main(String[] args) {
20+
21+
Demo1 obj = new Demo1();
22+
}
23+
24+
static int p = 99;
25+
26+
static {
27+
System.out.println("In Static block II");
28+
System.out.println(p);
29+
}
30+
31+
{
32+
System.out.println("In Instance block II ");
33+
}
34+
}

0 commit comments

Comments
 (0)