Abstract classes and Concrete classes

Source: Internet
Author: User

/*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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.