<pre name="code" class="java">package testBaidu;
public class Fruit {
static String color = "黃色";
String size = "大";
static String getFruitColor() {
return color;
}
public String getFruitSize() {
return size;
}
}
</pre><pre name="code" class="java">package testBaidu;
public class Apple extends Fruit{
static String appleColor = "綠色";
String appleSize = "小";
static String getFruitColor() {
return appleColor;
}
public String getFruitSize() {
return appleSize;
}
public static void main(String[] args) {
Fruit apple = new Apple();
System.out.println(apple.getFruitColor());
System.out.println(apple.getFruitSize());
}
}
打印結果:
黃色
小
子類繼承父類,重寫父類的靜態方法無效。