先这样这样
public class Pen {
String color= "黄色";
void hua() {
System.out .println("用黄色笔画画");
}
}
class Pencel extends Pen{
String color= "黑色"; //???
void hua() {
System.out .println("用黑色笔画画");
}
}
然后
public class Draw {
void draw(Pen p) {
System.out .println("笔是"+p.color+"颜色");
p.hua();
}
public static void main(String[] args) {
Draw h=new Draw();
h.draw(new Pencel());
}
}
为啥p.color那不是Pencel的color黑色,而是Pan的color黄色呢?
可以告诉我是哪方面的知识没学到吗??我我菜鸟。。谢谢!!!!!
https://www.jianshu.com/p/251...