abstract class Student
{
public abstract void study();
public void sleep()
{
System.out.println("躺着睡");
}
}
class BeasStudent extends Student
{
public void study()
{
System.out.println("beas study");
}
public void sleep()
{
System.out.println("坐着睡");
}
}
class AdvStudent extends Student
{
public void study()
{
System.out.println("Adv study");
}
}
方式一:
class Dosome
{
public static void dosome(Student s)
{
s.study();
s.sleep();
}
}
public class duotai
{
public static void main(String[] args)
{
Dosome doo=new Dosome();
doo.dosome(new BeasStudent());
doo.dosome(new AdvStudent());
}
}
方式二:
public class duotai
{
public static void main(String[] args)
{
dosome(new AdvStudent());
dosome(new BeasStudent());
}
public static void dosome(Student s)
{
s.study();
s.sleep();
}
}
问题是:
使用方法一时,Dosome类中dosome函数为什么不能加static,而方法二中,dosome函数必须加static。
|