最赞回答 / qq_苦笑释怀_0
上面的是把一个dog对象转换成Animal对象,下面的是把Animal对象强制转换成dog对象。animal包含dog,dog转成animal是没有问题的,但是animal转换成dog就存在溢出问题(即只有dog能够转换成功,其余cat等不能)
2018-02-28
已采纳回答 / CH灬
build path 出问题了 ,可以右键你的项目名称,选择Build path 里的configure build path 的libraries,看有没有红叉叉
2018-02-28
package hellopolymorphic;
public class plane extends traffic {
public plane() {
a="飞机";
b="天空";
c=500;
super.transport(this.a,this.b,this.c);
}
}
public class plane extends traffic {
public plane() {
a="飞机";
b="天空";
c=500;
super.transport(this.a,this.b,this.c);
}
}
2018-02-27
package hellopolymorphic;
public class ship extends traffic {
public ship() {
a="轮船";
b="海面";
c=200;
super.transport(this.a,this.b,this.c);
}
}
public class ship extends traffic {
public ship() {
a="轮船";
b="海面";
c=200;
super.transport(this.a,this.b,this.c);
}
}
2018-02-27
package hellopolymorphic;
public class bus extends traffic {
public bus(){
a="汽车";
b="陆地";
c=40;
super.transport(this.a,this.b,this.c);
}
}
public class bus extends traffic {
public bus(){
a="汽车";
b="陆地";
c=40;
super.transport(this.a,this.b,this.c);
}
}
2018-02-27
package hellopolymorphic;
public class traffic {
String a,b;
int c;
public void transport(String a,String b,int c) {
System.out.println(a+"可以在"+b+"上运输"+c+"人");
}
}
public class traffic {
String a,b;
int c;
public void transport(String a,String b,int c) {
System.out.println(a+"可以在"+b+"上运输"+c+"人");
}
}
2018-02-27
来交作业啦
package hellopolymorphic;
public class initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
traffic bus=new bus();
traffic ship=new ship();
traffic plane=new plane();
}
}
package hellopolymorphic;
public class initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
traffic bus=new bus();
traffic ship=new ship();
traffic plane=new plane();
}
}
2018-02-27