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