本帖最后由 yang9876q 于 2015-6-16 09:48 编辑
你这总共出现两种错误,一个是找不到Student(fangf方法的参数应该是student,而不应该是Student,因为你定义的是student类,小写的),一个是静态中引用非静态方法(错误原因:主函数是静态的,其调用的方法也应该是静态的,fangf方法你定义的是非静态的)。
正确程序如下:
- abstract class student
- {
- public abstract void study();
- public void sleep()
- {System.out.println("躺睡");}
- }
- class BaseStudent extends student
- {public void study()
- {System.out.println("base 学习");}
- public void sleep()
- {System.out.println("坐睡");}
- }
- class Advsstudent extends student
- {public void study()
- {System.out.println("adcs 学习");}
- }
- class duotaidemo
- {
- public static void main(String[] args)
- {BaseStudent as=new BaseStudent();
- as.study();
- as.sleep();
- Advsstudent ss=new Advsstudent();
- ss.study();
- ss.sleep();
- fangf(new BaseStudent());
- fangf(new Advsstudent());
- }
- public static void fangf(student ss)
- {
- ss.study();
- ss.sleep();
- }
- }
复制代码
|