Write a Java application that consists of 3 classes:theMonkey class,thepeople 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 , 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.
public class Monkey { public Monkey (String s) {System.out.println (s); public void speak () {System.out.println ( "babbling ..."
package Com.hanqi; public class People11 extends Monkey { public People11 (String s) { super (s); public void speak () {System.out.println ( "Sample, good! It's going to talk! "); public void think () {System.out.println () Don't talk! Think hard! "); }}
-
Package Com.hanqi; Public class E { publicstaticvoid main (string[] args) { // TODO Auto-generated method stubs Monkey m=new Monkey ("Little Monkey"); M.speak (); PEOPLE11 p=new People11 ("Human"); P.speak (); }}
Java Inheritance Exercises 4