成员变量的隐藏和方法的重写
Goods.java
public class Goods {
public double weight;
public void oldSetWeight(double w) {
weight=w;
System.out.println("double型的weight="+weight);
}
public double oldGetPrice() {
double price = weight*10;
return price;
}
}
CheapGoods.java
public class CheapGoods extends Goods {
public int weight;
public void newSetWeight(int w) {
weight=w;
System.out.println("int型的weight="+weight);
}
public double newGetPrice() {
double price = weight*10;
return price;
}
}
Example5_3.