Chinaunix首页 | 论坛 | 博客
  • 博客访问: 718960
  • 博文数量: 160
  • 博客积分: 8847
  • 博客等级: 中将
  • 技术积分: 1656
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-25 16:46
个人简介

。。。。。。。。。。。。。。。。。。。。。。

文章分类

全部博文(160)

文章存档

2015年(1)

2013年(1)

2012年(4)

2011年(26)

2010年(14)

2009年(36)

2008年(38)

2007年(39)

2006年(1)

分类: 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 + "咚咚咚。。。");
    }
}

阅读(1229) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~