forked from Hesenius/SafariJava17CertStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package init2; | ||
|
||
import static java.lang.System.out; | ||
|
||
class Parent { | ||
Parent(int x) { y += x; out.print(", P-c: y is " + y); } | ||
static { out.print(", P-si: x is " + Parent.x); } | ||
static int x = 99; | ||
int y = 100; | ||
{ y++; out.print(", P-i: y is " + y); } | ||
} | ||
class Child extends Parent { | ||
int x = 200; | ||
static int y = 300; | ||
Child() { super(y); } | ||
Child(int x) { this(); } | ||
{ out.print(", C-i x: is " + x); } | ||
static { out.print(", C-si: y is " + y); } | ||
} | ||
class InitOrder3 { | ||
public static void main(String[] args) { | ||
out.print("Hello!"); | ||
new Child(-1); | ||
out.println(" Goodbye!"); | ||
} | ||
} | ||
public class Q { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package initialization; | ||
|
||
class LazyP { | ||
int p = getOneHundred(); | ||
static { | ||
System.out.println("loading LazyP"); | ||
} | ||
int getOneHundred() { | ||
System.out.println("LazyP getOneHundred"); | ||
return 100; | ||
} | ||
int getP() { | ||
return p; | ||
} | ||
} | ||
class Lazy extends LazyP { | ||
{ | ||
System.out.println("running instance init in Lazy (1), x is " + this.x); | ||
} | ||
int x = 100; | ||
{ | ||
System.out.println("running instance init in Lazy (2), x is " + x); | ||
} | ||
|
||
|
||
public Lazy() { | ||
super(); | ||
// right here, compiler adds "instance initialization" | ||
System.out.println("back from super()"); | ||
} | ||
public Lazy(int x) { | ||
this(); | ||
// nothing special here... it all happened in and immediately after | ||
// super() call above | ||
} | ||
static int getValue() { | ||
System.out.println("getting value"); | ||
return 10; | ||
} | ||
static { | ||
System.out.println("loading Lazy, value is " + Lazy.value); | ||
} | ||
static int value = getValue(); | ||
static { | ||
System.out.println("loading Lazy (step 2), value is " + Lazy.value); | ||
} | ||
|
||
int val = 200; | ||
@Override | ||
int getOneHundred() { | ||
return val; | ||
} | ||
} | ||
|
||
public class LazyLoad { | ||
public static void main(String[] args) { | ||
System.out.println("step 1"); | ||
Lazy l; | ||
System.out.println("step 2"); | ||
System.out.println("Class of Lazy is " + Lazy.class); | ||
System.out.println("step 3a"); | ||
System.out.println(Lazy.value); | ||
System.out.println("step 3"); | ||
l = new Lazy(); | ||
System.out.println("step 4"); | ||
System.out.println("p value is " + l.p); | ||
} | ||
} |