. 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