Abstract class animal{
???? Public abstractvoid eat ();
}
class Dog extends animal{
???? Public void eat () {
???????? System. out. println (" The dog eats bones . ");
????}
}
class Cat extends animal{
???? Public void eat () {
???????? System. out. println (" The cat eats the mouse ");
????}
}
class Wolf extends animal{
???? Public void eat () {
???????? System. out. println (" Eat Pleasant goat ");
????}
}
class Test02 {
???? Public staticvoid main (String args[]) {
???????? Animal aa[]=new animal[3];
????????
???????? aa[0]=New Dog ();
???????? aa[1]=New Cat ();
???????? aa[2]=New Wolf ();
???????? For (int i=0;i<3;i++)
???????????? {aa[i].eat ();}
????}
}
/*
Experimental results:
The dog eats bones.
The cat eats the mouse
Eat Pleasant goat
?
Abstract class: A class that can only be inherited as a parent class and cannot be instantiated
?
Why do you need abstract classes?
???? In some cases not all classes can fully describe the behavior of the class, only know what methods should be included,
???? but without knowing what to do, you can define abstract classes without having to implement their methods.
?
Abstract classes can contain abstract and non-abstract methods,
It is also possible to not include abstract and non-abstract methods.
as long as there is an abstract method, it is an abstract class. ????
?????
????
*/
Java abstract class