当前位置: 技术问答>java相关
请教一个Java初学者的问题!
来源: 互联网 发布时间:2015-07-02
本文导语: 编译提示 I:workspacejavaMyGameRobLordtest.java:10: non-static method MyGod() cannot be referenced from a static context 是面向对象没有学好,请高手讲讲。 public class test{ static void main (String[] arg){ Plan Wife,God; Wife = ...
编译提示
I:workspacejavaMyGameRobLordtest.java:10: non-static method MyGod() cannot be referenced from a static context
是面向对象没有学好,请高手讲讲。
public class test{
static void main (String[] arg){
Plan Wife,God;
Wife = new Plan("");
Wife.prt();
Wife = MyGod();
//负值
God = Wife;
God.prt();
//修改
God.name = "god plan";
System.out.println("修改后");
God.prt();
Wife.prt();
}
public Plan MyGod(){
return new Plan("huyang-->2");
}
}
class Plan{
String name;
Plan(String name){
this.name = name;
}
public void prt(){
System.out.println(this.name);
}
}
I:workspacejavaMyGameRobLordtest.java:10: non-static method MyGod() cannot be referenced from a static context
是面向对象没有学好,请高手讲讲。
public class test{
static void main (String[] arg){
Plan Wife,God;
Wife = new Plan("");
Wife.prt();
Wife = MyGod();
//负值
God = Wife;
God.prt();
//修改
God.name = "god plan";
System.out.println("修改后");
God.prt();
Wife.prt();
}
public Plan MyGod(){
return new Plan("huyang-->2");
}
}
class Plan{
String name;
Plan(String name){
this.name = name;
}
public void prt(){
System.out.println(this.name);
}
}
|
拜托, 你的
public Plan MyGod(){
return new Plan("huyang-->2");
}又不是static的!!
public Plan MyGod(){
return new Plan("huyang-->2");
}又不是static的!!