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());
}
}
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());
}
}