Java interface Exercise: Look at the following diagram to implement the following interfaces and classes, and complete the main method in adventure.

Source: Internet
Author: User

 Package Pack1;  Public Interface canfly {    void  fly ();}
 Package Pack1;  Public Interface canswim {    void  swim ();}
 Package Pack1;  Public Abstract  class actioncharacter {    abstractvoid  Fight (String EMP);     void speak (String s)    {        System.out.println (s);    }}
 PackagePack1; Public classHeroextendsActioncharacterImplementsCanswim, canfly {String name;  PublicHero (String name) {Super();  This. Name =name; } @Override Public voidFly () {System.out.println ( This. name+ "Can Fly"); } @Override Public voidswim () {System.out.println ( This. name+ "Can Swim"); } @OverridevoidFight (String EMP) {System.out.println ( This. name+ "It's a tough fight."); }}
 PackagePack1; Public classAdventure { Public Static voidMain (string[] args) {Hero HB=NewHero ("Superman");        Hb.swim ();        Hb.fly (); Hb.fight (NULL); Canfly CF=HB;        Cf.fly (); Canswim CS=HB;        Cs.swim (); Actioncharacter AC=HB; Ac.fight (Superman); Ac.speak (Hello); }}

Java interface Exercise: Look at implementing the following interfaces and classes, and complete the main method in adventure.

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.