刘军的博客liujun.blog.chinaunix.net
liu1084
。。。。。。。。。。。。。。。。。。。。。。
全部博文(160)
2015年(1)
2013年(1)
2012年(4)
2011年(26)
2010年(14)
2009年(36)
2008年(38)
2007年(39)
2006年(1)
athzhang
Elaine_w
linky521
2909157
Nine_Sun
embeded-
sjtlqy
subukena
jiannma
heu
cgweb
格伯纳
浪花小雨
duke217
reyleon
daniel20
zxcbvbbb
qwxren
分类: Java
2008-11-06 19:55:34
package Testphlymoph; import java.util.*; /** 多态,也叫动态绑定或者池绑定 * 多态帮助java程序的可扩展性发挥到了极致 * 多态的实现条件:1:有继承;2:有重写;3:父类对象引用子类对象 * */ public class TestPhlymoph { public static void main(String[] args) { // TODO Auto-generated method stub Student s = new SchoolChild(); s.name = "liujun"; s.goToSchool(s); s = new CollegeStudent(); s.name = "cookie"; s.goToSchool(s); } } //学生 class Student{ String name; Date d = new Date(); int hour = d.getHours(); public void goToSchool(Student stu){ Student me = new Student(); if (this.hour <= 7 && this.hour > 5){ this.clockMe(me); }else{ System.out.println("洗脸刷牙"); } } public void clockMe(Student me){ System.out.println(this.name + "叮铃铃。。。"); } } //小学生 class SchoolChild extends Student{ public void goToSchool(Student stu){ SchoolChild me = new SchoolChild(); if (this.hour <= 6 && this.hour > 5){ this.clockMe(me); }else{ System.out.println("锻炼身体1111"); } } public void clockMe(Student me){ System.out.println(this.name + "咕咕咕。。。"); } } //大学生 class CollegeStudent extends Student{ public void goToSchool(Student stu){ CollegeStudent me = new CollegeStudent(); if (this.hour <= 9 && this.hour > 5){ this.clockMe(me); }else{ System.out.println("继续睡觉11111"); } } public void clockMe(Student me){ System.out.println(this.name + "咚咚咚。。。"); } }
上一篇:jquery树状目录--超简单的js
下一篇:java中对象转换
登录 注册