A question about down-casting

sailor (Sailor)
Question: Is "a1" an instance of "Animal", or "Snake" ? why?

If I remove "abstract" from the definition of class Animal, what's the running result ?

//: TestAnimal.java
abstract class Animal
{
public void move()
{
System.out.println("moving...") ;
}
}

class Snake extends Animal
{
public void move()
{
System.out.println("crawling") ;
}
}

class TestAnimal
{
static public void main(String args[])
{
Animal a1 = new Snake() ;
Snake s1 = new Snake() ;
a1.move() ;
s1.move() ;

System.out.println(a1.getClass().toString());
System.out.println(s1.getClass().toString());
}

}
(#8409@0)
2000-9-11 -05:00

回到话题: A question about down-casting

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=8409