本帖最后由 iceeyes992 于 2011-12-26 16:35 编辑
代码如下
abstract class Student
{
public abstract void study();
public void sleep()
{
System.out.println("sleep in night on the bed!");
}
}
class BaseStudent extends Student
{
public void sutdy()
{
System.out.println("base study!");
}
public void sleep()
{
System.out.println("sleep in day on the chair!");
}
}
class AdvStudent extends Student
{
public void sutdy(){
System.out.println("adv study!");
}
public void sleep()
{
System.out.println("sleep in day on the chair in classroom!");
}
}
class DoStudent
{
public void dosomething(Student stu)
{
stu.study();
stu.sleep();
}
}
public class StudentTest
{
public static void main(String[] args)
{
//BaseStudent bs = new BaseStudent();
//bs.study();
//bs.sleep();
//AdvStudent as = new AdvStudent();
//as.study();
//as.sleep();
DoStudent ds = new DoStudent();
ds.dosomething(new BaseStudent());
ds.dosomething(new AdvStudent());
}
}
编译提示BaseStudent和AdvStudent is not abstract and does not override abstract method study() in Student
为什么呢?怎么解决? 谢谢啦! |