/*2. Abstract classes and Concrete classes
* Abstract can be used to define classes and methods
* Abstract method without method body */
1 Abstract classanimals{2 String name;3 String food;4 5 Public Abstract voideat ();6 Public Abstract voidroam ();7 8 }9 Ten Abstract classCanineextendsanimals{ One //canine do not necessarily implement the method of parent class animal A Public voideat () { -System.out.println ("Dog animals are eating!") "); - } the } - Public classTwochouextendscanine{ - //because Twochou is not an abstract class, it implements a method that the parent class does not implement in the subclass . - //If the Eat method is implemented here, the Eat method is rewritten + Public voidRoam () { -System.out.println ("The dog likes Sahuan to run!") "); + } A Public Static voidMain (string[] args) { atTwochou d =NewTwochou (); - d.eat (); - D.roam (); - } -}
Abstract classes and Concrete classes