Thinking in Java(2)---初始化
ok,今天我看到在Thinking in java中的内容和大家共享下,总是忘记更新自己的简书,这点向大家说声sorry.
java 提供了一种成员变量必须初始化的机制,就是说任何的成员变量必须初始化,否则Java会提供该成员变量的数据类型的默认值
代码如下:
public class IniiialValues {
boolean b;
char c;
byte byt;
short s;
int i;
long l;
float f;
double d;
void print() {
System.out.println("Date type:[]" + "boolean =" + b + "");
System.out.println("Date type:[]" + "char =" + c + "");
System.out.println("Date type:[]" + "byte =" + c + "");
System.out.println("Date type:[]" + "short =" + s + "");
System.out.println("Date type:[]" + "int =" + i + "");
System.out.println("Date type:[]" + "long =" + l + "");
System.out.println("Date type:[]" + "float =" + f + "");
System.out.println("Date type:[]" + "double =" + d + "");
}
public static void main(String[] args) {
IniiialValues i = new IniiialValues();
i.print();
}}
在Java中变量定义的顺序,决定了变量的初始化的顺序