public class Test
{
public static void main(String[] args)
{
int mi=getM();//换成this.getM()也不行。
System.out.println(mi);
}
public void setM()
{
m=100;
}
public int getM()
{
return m;
} private int m;}
==============
为什么会有这样的提示?Test.java:5: non-static method getM() cannot be referenced from a static context
难道main()里只能调用static方法吗?
{
public static void main(String[] args)
{
int mi=getM();//换成this.getM()也不行。
System.out.println(mi);
}
public void setM()
{
m=100;
}
public int getM()
{
return m;
} private int m;}
==============
为什么会有这样的提示?Test.java:5: non-static method getM() cannot be referenced from a static context
难道main()里只能调用static方法吗?
public static void main(String[] args)
{
Test t = new Test();
int mi=t.getM();//换成this.getM()也不行。
System.out.println(mi);
}
你要先定义对象,才能用他的方法啊