abstract class b
{
abstract void user();
}class c extends b
{
void user()
{
System.out.println("Hello Hacksign!");
}
}public class test extends c
{
public void main(String [] args)
{
user();
}
}
编译通过,但是运行错误:
Exception in thread "main" java.lang.NoSuchMethodError: main这里有两个问题
1、为什么main方法需要为static类型?
2、我将main方法定义为static类型后,编译提示无法从静态方法中引用非静态方法,将user()前加上static关键字后,又报错不能实现user()方法郁闷,为什么?

解决方案 »

  1.   

    1、自己到网上去找,或是去看书,多的是!
    2、你没有声明对象,怎么能够去操作方法呢????
    ========================================
    public static void main(String [] args) 

    test t = new test();
    t.user(); 

    ========================================
    PS:强烈建议楼主去打基础!
      

  2.   

    有的东西要死记,就像main函数为static这样的,static main()方法是一个应用程序的入口,它属于c 类,但你开始执行main的时候没有实例化这个类c ,那怎么调用?只能static了,这只是我的想法而已,因为user()是not static  方法,所以,你首先有个含有这个方法的引用,也就是说这个类c的实例!除非你把这个方法改为static,public class test extends c 

    public void main(String [] args) 

    new c().user();