对象导论

  每个对象都提供服务

light  

on();

off();

bright();

dim();

light是类名,下面部分是方法接口。

对象的向上转型具体实现:

 1 public class shape {
 2     void erase(){
 3         
 4     }
 5 }
 6 
 7 public class circle extends shape{
 8     void erase(){
 9         System.out.print("this is a circle");
10     }
11 }
12 
13 public class square extends shape {
14     void erase(){
15         System.out.print("this is a squara");
16     }
17 }
18 
19 public class upcasting {
20     void dosomething(shape s){
21         s.erase();
22     }
23     public static void main(String[] args) {
24         // TODO Auto-generated method stub
25         shape c = new circle();
26         shape s = new square();
27         upcasting up = new upcasting();
28         up.dosomething(c);
29         up.dosomething(s);
30         
31     }
32 
33 }

 

posted @ 2016-06-14 17:13  单链表  阅读(98)  评论(0编辑  收藏  举报