Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
37 lines (33 loc) · 1.12 KB

File metadata and controls

37 lines (33 loc) · 1.12 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
37
package ClassTest;
class SingleTon {
private static SingleTon singleTon = new SingleTon();
public static int count1;
public static int count2 = 0;
private SingleTon() {
count1++;
count2++;
}
public static SingleTon getInstance() {
return singleTon;
}
}
/*
*详解类加载过程
* */
public class ClassLoadTest {
public static void main(String[] args) {
SingleTon singleTon = SingleTon.getInstance();
//调用类的静态方法,触发类的初始化过程,加载->验证->准备
/*
*准备阶段为类的静态变量分配内存并将其初始化为0或者null,准备阶段不分配类中的实例变量的内存
* */
/*
准备->解析->初始化
初始化阶段是执行类构造器<clinit>()方法的过程。
<clinit>()方法方法是由编译器自动收集类中的所有类变量的赋值动作
和静态语句块(static{}块)中的语句合并产生的。
* */
System.out.println("count1=" + singleTon.count1);
System.out.println("count2=" + singleTon.count2);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.