继承—Monkey

1 public class Monkey {
2     public void Monkey(String s){
3         
4     }
5     public void speak(){
6         System.out.println("吱……吱……");
7     }
8 
9 }
 1 public class People extends Monkey {
 2     
 3     public void speak(){
 4         System.out.println("小样儿,不错嘛,会说话了");
 5     }
 6     
 7     public void think(){
 8         System.out.println("别说话!认真思考!");
 9     }
10 
11     
12 }
 1 public class TextMP {
 2 
 3     public static void main(String[] args) {
 4         
 5         Monkey m=new Monkey();
 6         m.speak();
 7         
 8         People p=new People();
 9         p.speak();
10         p.think();
11 
12     }
13 
14 }

结果:

posted @ 2016-05-23 08:31  唐枫  阅读(115)  评论(0编辑  收藏  举报