标签:
Java.Variable
实例变量永远都会有默认值。如果你没有明确地赋值给实例变量,或者没有调用setter,实例变量还是会有值。
intergers 0
floating points 0.0
booleans false
references null
package chap04;
public class PoorDogTestDrive {
public static void main(String[] args)
{
PoorDog one = new PoorDog();
System.out.println("Dog size is " + one.getSize());
System.out.println("Dog name is " + one.getName());
}
}
class PoorDog
{
private int size;
private String name;
public int getSize() {
return size;
}
public String getName() {
return name;
}
}
返回结果:
Dog size is 0
Dog name is null
(要记得null代表没有操作对象的远程控制,它是个引用而不是对象)
标签:
原文地址:http://www.cnblogs.com/fatoland/p/4178385.html