Java basics, inheriting class title: Write a Java application that consists of 3 classes: The Monkey class, the People class, and the main class E

Source: Internet
Author: User

21. Write a Java application that consists of 3 classes: The Monkey class, the People class, and the main class

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, in the Speak method

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

(3) Add method void Think () in the People class and output "Don't talk!" in the Think method. Think hard! ”

The information.

(4) In main class E, the main method of creating monkey and people class object class test the work of these 2 classes

Yes. 、

 Package Zhongqiuzuoye;  Public class Monkey {    Monkey (String s)  // construction     {}        public  void  speak ()    {        System.out.println ("babbling ...");}    }
 PackageZhongqiuzuoye; Public classPeople1extendsmonkey{People1 (String s) {Super(s); //TODO Auto-generated constructor stub    }         Public voidspeak () {System.out.println ("Good for a small sample" It's going to talk! "); }     Public voidThink () {System.out.println ("Don't Talk! Think hard! "); }    }
 Package Zhongqiuzuoye;  Public class E1 {    publicstaticvoid  main (string[] args) {        // TODO Auto-generated method stubs New Monkey ("Tom");                          M.speak ();                 New People1 ("Xiaoming");        P.speak ();        P.think ();            }}

Java basics, inheriting class title: Write a Java application that consists of 3 classes: The Monkey class, the People class, and the main class E

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.