Create a Cat Cat, Animal and write play method output
"I'm a cat, I play ball";
Create a dog, the realization of Animal and write output methods of play "I
Is a dog, I play ball ",
Write a test class TestDemo, through the polymorphic transformation (up) to create a cat,
Through the polymorphic transformation (up) to create a dog, and call play method respectively,
CodePudding user response:
package com;
Public class Cat implements Animal {
@ Override
Public void play () {
System. The out. Println (" you are a cat, happy star cat ");
}
}
CodePudding user response:
package com;
Public class Gou implements Animal {
@ Override
Public void play () {
System. The out. Printf (" wang fellow villager, clan ");
}
}
package com;
Public abstract interface Animal {
Public abstract void play ();
}
package com;
Public class TestDemo {
Public static void main (String [] args) {
The Cat MAO=new (Cat);
Gou Gou=new Gou ();
MAO. The play ();
Gou. Play ();
}
}