class Price {
final static Price INSTANCE = new Price(2.8);
static double initPrice = 20;
double currentPrice;
public Price(double discount){
currentPrice = initPrice - discount;
}
}
public class SubClass {
public static void main(String[] args) throws Exception{
System.out.println(Price.INSTANCE .currentPrice);
Price p = new Price(2.8);
System.out.println(p .currentPrice);
}
}
在别处看的一段代码,本以为会同时输出17.2,结果却是-2.8,17.2。