Learn from Teacher Wang interface: (v) Example: the reconstruction of electronic pet system

Source: Internet
Author: User
Reconstructing the electronic pet system teacher: Wang Shaohua QQ Group No.: 483773664
First, reconstruct the demand
  1. Define the Eatable interface, define the Eat () method in the interface, and indicate the eating function

  2. Define the Flyingdisccatchable interface, define the Catchingflydisc () method in the interface, and indicate the ability to pick up the Frisbee

  3. Define the Swimmable interface, define the swim () method in the interface, and indicate the game function

  4. Defines abstract class pet, including pet name, health value (Heath) and intimacy with host (Love) attribute, and provides abstract method print (), used to export pet information

  5. Define dog classes, inherit pet classes, implement Eatable, flyingdisccatchable interfaces, and override or implement each method

  6. Define Penguin Class Penguin, inherit the pet class, implement eatable and Swimmable interfaces, and override or implement each method

  7. Write test classes that enable dogs to eat, penguin games and dogs to play with frisbee games and output penguin messages.

Second, reference code




From for notes (Wiz)

Learn from Teacher Wang interface: (v) Example: the reconstruction of electronic pet system

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.