本帖最后由 shw16888 于 2015-4-8 14:36 编辑
- /*
- 基础班学生:
- 学习,睡觉
- 高级班学生:
- 学习,睡觉
- 可以将这两类事物进行抽取
- 多态简化了对象的调用
- */
- abstract class Student
- {
- public abstract void study();
- public void sleep()
- {
- System.out.println("躺着睡");
- }
- }
- class Basestudent extends Student
- {
- public void study(){
-
- System.out.println("base study");
- }
- }
- class Advstudent extends Student
- {
- public void study(){
-
- System.out.println("adv study");
- }
- public void sleep()
- {
- System.out.println("坐着睡");
- }
- }
- class Dostudent
- {
- public static void doSome(Student s)
- {
- s.study();
- s.sleep();
-
- }
- }
- class DuotaiDemo4
- {
- public static void main(String[] args)
- {
- Dostudent d=new Dostudent();
- d.doSome(new Basestudent());
- d.doSome(new Advstudent());
- }
- }
复制代码
|
|