请教一个Java初学者的问题!

tobato tobato 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
编译提示
I:\workspace\java\MyGame\RobLord\test.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);
}
}

...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
tobato
Java SE 62,621 成员 307,251 内容