当你new Sub()时,System.out.println(""); 也会被当作private String str;一样被先运行的
解决方案 »
- java线程问题,为什么有些代码不能在主线程里面运行
- xml解析
- csv文件当中显示日期的问题!!
- 为什么Cat mimi = new Cat("mimi"); Cat cici = new Cat("cici"); 中的cici要加引号》?如果我定义的构造函数是Cat(double x){}那么我再new一个cat需要加引号?
- 急!!!请问怎么获得当前页面的分辨率
- jsp页中怎样生成动态表格(求代码)
- 在java程序中,怎样实现获得本地站点与远程站点之间的网络传输速度?
- 如何获取某个字符的ASCII码?
- Eclipse编译 和 CMD编译 java的区别
- 请教各位高手一个简单问题,急
- 小弟昨天装了英文版(WIN ME)系统,怎么才能显示中文?
- 为什么Java的DOS命令使用不了
System.out.println("");被运行了!
你也喜欢麻辣教师吗,我很喜欢阿
比如说class.forName();
8.7 Static Initializers
Any static initializers declared in a class are executed when the class is initialized and, together with any field initializers (§8.3.2) for class variables, may be used to initialize the class variables of the class (§12.4).
StaticInitializer:
static Block
It is a compile-time error for a static initializer to be able to complete abruptly (§14.1, §15.6) with a checked exception (§11.2). It is a compile-time error if a static initializer cannot complete normally (§14.20).
The static initializers and class variable initializers are executed in textual order.
Use of class variables whose declarations appear textually after the use is sometimes restricted, even though these class variables are in scope. See §8.3.2.3 for the precise rules governing forward reference to class variables.
If a return statement (§14.16) appears anywhere within a static initializer, then a compile-time error occurs.
If the keyword this (§15.8.3) or the keyword super (§15.11, §15.12) appears anywhere within a static initializer, then a compile-time error occurs
static{
}块
那么是不是 不加static
就只有 调用构造函数时才会被运行啊
而加了static 在类被初始化的时候就运行了