A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王德升 中级黑马   /  2012-5-10 17:31  /  2344 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 王德升 于 2012-6-3 23:15 编辑

class Animal{
public String name;
Animal(String name){
  this.name=name;
}
}

class Cat extends Animal{
public String eyesColor;
Cat(String n,String s){
  super(n);
  eyesColor=s;
}

}

class Dog1 extends Animal{
public String furColor;
Dog1(String n,String s){
  super(n);
  furColor=s;
}
}
public class TestAnimal {
public static void main(String args[]){
  Animal a=new Animal("name");
  a=new Dog1("bigyellow","yellow");
  System.out.print(a.furColor);
  System.out.print(a instanceof Dog1);
}
}
我不懂,为什么在这里a是Dog1类型的。
但是却不能调用furColor呢,?  

评分

参与人数 1技术分 +1 收起 理由
攻城狮 + 1 赞一个!

查看全部评分

9 个回复

倒序浏览
您需要登录后才可以回帖 登录 | 加入黑马