码迷,mamicode.com
首页 > 其他好文 > 详细

对象导论

时间:2016-06-14 17:47:13      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

  每个对象都提供服务

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 }

 

对象导论

标签:

原文地址:http://www.cnblogs.com/justtofun/p/5584721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!