0
Sentence wrong?
Animal a=new Animal; ((Cat)a).makesound(); It can't work!!
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
0
what is it you want your code to do? make cat sounds?
0
This the sentence from the lesson "downcasting", I think so, but from the original it doesn't seem to work,lol...
- 1
Animal a=new Cat();
((Cat)a).makeSound();
maybe it works.