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()方法郁闷,为什么?
{
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()方法郁闷,为什么?
2、你没有声明对象,怎么能够去操作方法呢????
========================================
public static void main(String [] args)
{
test t = new test();
t.user();
}
========================================
PS:强烈建议楼主去打基础!
{
public void main(String [] args)
{
new c().user();
}
}