File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,13 @@ class demo3{
6
6
7
7
void fun (){
8
8
String str2 = "Shashi" ;
9
+ // System.out.println(System.identityHashCode(str2));
9
10
String str3 = new String ("Core2Web" );
10
11
}
11
12
12
13
public static void main (String [] args ) {
13
14
demo3 obj = new demo3 ();
15
+ // System.out.println(System.identityHashCode(obj.str1));
14
16
15
17
obj .fun ();
16
18
}
Original file line number Diff line number Diff line change 2
2
3
3
public class program3 {
4
4
5
- int x = 10 ;
5
+ static int x ;
6
+
7
+ static {
8
+ System .out .println ("In static block 1" +x );
9
+ }
6
10
7
11
{
8
12
System .out .println ("instatnce block" );
@@ -16,8 +20,14 @@ public class program3 {
16
20
17
21
public static void main (String [] args ) {
18
22
19
- program3 obj = new program3 ();
23
+ // program3 obj = new program3();
24
+ x = 10 ;
25
+
26
+
27
+ }
20
28
29
+ static {
30
+ System .out .println ("In static block 2" +x );
21
31
}
22
32
23
33
{
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments