0

Sentence wrong?

Animal a=new Animal; ((Cat)a).makesound(); It can't work!!

9th Aug 2016, 11:27 PM
solsir
4 ответов
+ 2
Your code is casting Animal as a cat. Cat is a Animal not Animal is a cat. Here's a link for some reading on the subject. http://www.cs.utexas.edu/~cannata/cs345/Class%20Notes/14%20Java%20Upcasting%20Downcasting.htm
10th Aug 2016, 1:13 AM
James
James - avatar
0
what is it you want your code to do? make cat sounds?
9th Aug 2016, 11:54 PM
Aquarius
Aquarius - avatar
0
This the sentence from the lesson "downcasting", I think so, but from the original it doesn't seem to work,lol...
9th Aug 2016, 11:58 PM
solsir
- 1
Animal a=new Cat(); ((Cat)a).makeSound(); maybe it works.
10th Aug 2016, 2:35 AM
Byungwook Lee
Byungwook Lee - avatar