Inherit 4-monkey

Source: Internet
Author: User

. Write a Java application that consists of 3 classes:Monkey class,people Classes and Main classes

E. Requirements:

(1) There is a construction method in the Monkey class:Monkey (String s), and there is a public void speak ()

method to output the message "babbling ..." in the speak method.

(2) The people class is a Subclass of the Monkey class, overriding the method speak () in the people class , Speak Method

In the output "sample, good!" It's going to talk! "Information.

(3) in the people new methods in class void Think () , in Think output from the method "Don't talk! Think hard! "

The information.

(4) in the main class E of the Main method is created in the Monkey with the people class of the object class to test this 2 the function of a class

Yes.

1  PackageMianxiangduixiang;2 3  Public classMonkey {4  5      Public voidMonkey (String s)6     {7 System.out.println (s);8     }9      Public voidspeak ()Ten     { OneSystem.out.println ("Babbling ... "); A     } -}

1  PackageMianxiangduixiang;2 3  Public classMpeopleextendsMonkey {4 5      Public voidspeak ()6     {7System.out.println ("Small sample, good!") It's going to talk! ");8     }9      Public voidThink ()Ten     { OneSystem.out.println ("Don't Talk! Think hard! "); A     } -}

1  PackageMianxiangduixiang;2 3  Public classE {4 5      Public Static voidMain (string[] args) {6         //TODO Auto-generated method stubs7 8Monkey m=NewMonkey ();9 m.speak ();TenMpeople mp=Newmpeople (); One mp.speak (); A Mp.think (); -     } -  the}

Inherit 4-monkey

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.