为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

4 回答

animal强制转换成Cat类,这个是老师举的一个错误的例子。为什么会报错呢?是因为Cat跟animal不相配,没先把cat对象自动转换成animal,解决方法:在cat强制转换上一行加上“Ainmal ainmal = cat;”并且别忘了先创建cat对象“”

0 回复 有任何疑惑可以回复我~

你创建Cat这个类了么

0 回复 有任何疑惑可以回复我~

another sample: //char < float;char < double;float < double

float f1 = 1.5f;

double d1= f1;

float f2 =(float) d1; //safe , system will not report error.

char c1= (char) d1; // error, coz the result is not expected

0 回复 有任何疑惑可以回复我~

you can add bellowing:  //reason the ture for animal stands for the reference variable which means that it 's a way to point to the created Dog objective

Cat cat = new Cat(); // create a new cat type objective

Animal animal2 = cat; // assign the reference to a big type named animal2

Cat cat = (Cat) animal2; // cut down the extend length

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么我的用了Cat还有错误

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信