我一直在写一个RPG-ish游戏作为Java的(重新)学习工具,但是看到在这个网站上发布代码有点困难,我做了一个简化版本来发布
调用人员 getter 时,God 类出现编译错误(找不到符号)
class God{
psvm(s [] args){
s.o.p("I create people and stuff and try to tell you about it")
People godsCreatedPerson = new People();
Stuff godsCreatedStuffForTheCreatedPerson = new Stuff();
s.o.p("Im the persons creator, so I should know stuff about him and his stuff");
s.o.p("Im going to try to tell you about my created person now:" + godsCreatedPerson.getPeopleNumberOfLegs); //error cannot find symbol
s.o.p("Im going to try again:" + godsCreatedPerson.getPeopleNumberOfFingers); //error cannot find symbol
s.o.p("but I cant tell you, even though I created this person, and I have his getters")
}
}
调用由 God 类创建的 Stuff 对象时,People 类上出现另一个编译错误(也找不到符号)
class People{
s.o.p("I have setters");
s.o.p("I have getters for my creator, so I can tell him about myself");
public int getPeopleNumberOfLegs(){
return myNumberOfLegs;
}
public int getPeopleNumberOfFingers(){
return myNumberOfFingers;
}
void imGoingToTryToDoSomethingWithTheStuffIOwnButDidntCreate(){
personsAttempt = godsCreatedStuffForTheCreatedPerson.doSomethingWithMe() //Person = God.Stuff
s.o.p("hmm it seems I cant do it, because I didnt CREATE the stuff"); //error cannot find symbol
}
}
Stuff 类没有错误,因为它不调用 God 或 Person 类
class Stuff{
s.o.p("i have getters and setters");
s.o.p("i have methods too!!");
void doSomethingWithMe(){
}
s.o.p("no problems with me, because I dont call my creator nor my owner");
}