W
www
Hi,
I have three classes(Animal, Cat and Dog).
public class Animal
{
//...
public void printOut()
{
System.out.println( + " is cute!"); //un-finished. My questions is below
}
}
public class Cat extends Animal
{
//...
}
public class Dog extends Animal
{
//...
}
I want to achieve the following:
Cat myCat = new Cat();
myCat.printOut(); //"Cat is cute!"
Dog myDog = new Dog();
myDog.printOut(); //"Dog is cute!"
Is this possible? Only one printOut() in all three classes, and that is
in superclass Animal. I don't want to over-write printOut() in Cat or Dog.
Thank you very much.
I have three classes(Animal, Cat and Dog).
public class Animal
{
//...
public void printOut()
{
System.out.println( + " is cute!"); //un-finished. My questions is below
}
}
public class Cat extends Animal
{
//...
}
public class Dog extends Animal
{
//...
}
I want to achieve the following:
Cat myCat = new Cat();
myCat.printOut(); //"Cat is cute!"
Dog myDog = new Dog();
myDog.printOut(); //"Dog is cute!"
Is this possible? Only one printOut() in all three classes, and that is
in superclass Animal. I don't want to over-write printOut() in Cat or Dog.
Thank you very much.