代码如下
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
为什么呢?怎么解决? 谢谢啦!作者: 刘忠德 时间: 2011-12-26 16:30
public void sutdy()是不是拼写错误了~~?作者: 于冰 时间: 2011-12-26 16:34
晕死过去~~~
谢谢楼上滴~~作者: 于冰 时间: 2011-12-26 16:34 本帖最后由 iceeyes992 于 2011-12-26 16:36 编辑