-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSweetShop.java
More file actions
36 lines (32 loc) · 838 Bytes
/
Copy pathSweetShop.java
File metadata and controls
36 lines (32 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ClassObject;
class Candy {
static {
System.out.println("loading candy");
}
}
class Gum {
static {
System.out.println("loading gum");
}
}
class Cookie {
static {
System.out.println("loading cookie");
}
}
public class SweetShop {
public static void main(String[] args) {
System.out.println("inside main");
new Candy();
System.out.println("After creating candy");
try {
//调用Class.forName,如果类未被加载,则加载
Class.forName("ClassObject.Gum");
} catch (ClassNotFoundException e) {
System.out.println("Error======== : Could't find Gum");
}
System.out.println("After Class.forname Gum");
new Cookie();
System.out.println("After creating cookie");
}
}