首页 > 代码库 > 多态-实例
多态-实例
/**
* Created by rabbit on 2014-07-10.
*/
abstract class student
{
public abstract void study();
public abstract void sleep();
}
class Basestudent extends student
{
public void study()
{
System.out.println("Base study");
}
public void sleep()
{
System.out.println("坐着睡");
}
public void eat()
{
System.out.println("坐着吃饭");
}
}
class Advstudent extends student
{
public void study()
{
System.out.println("Adv study");
}
public void sleep()
{
System.out.println("躺着睡");
}
}
class Dostudent
{
public void doSome(student stu)
{
stu.study();
stu.sleep();
}
}
public class DuoTaiDemo
{
public static void main(String [] args)
{
Dostudent ds = new Dostudent();
ds.doSome(new Basestudent());
ds.doSome(new Advstudent());
}
}