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 Text1;public class Monkey {///(1) Monkey class has a constructor method: Monkey (String s), and a public void speak ()//method, output in Speak method "babbling ... "information. Monkey (String s) {System.out.println (s);} public void Speak () {System.out.println ("babbling ...");}}
Package Text1;public class People1 extends Monkey {People1 (String s) {super (s);//TODO auto-generated constructor stub}//(2) The People class is a subclass of the Monkey class, overriding the method speak () in the People class, and outputting the "sample" in the Speak Method//. 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! "//information. public void speak () {System.out.println ("The sample is good! It's going to talk! ");} void Think () {System.out.println ("Don't talk!) ");}}
Package Text1;public class E {public static void main (string[] args) {//TODO auto-generated method stub//(4) in main class E's Main method to create monkey and people class The object class tests the work//energy of these 2 classes. Monkey m=new Monkey ("monkey");//Test Monkey Class M.speak (); People1 p=new People1 ("human");//Test People1 Class P.speak ();p. Think ();}}
Java Inheritance--4