<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());
}
}
打印结果:
黄色
小
子类继承父类,重写父类的静态方法无效。