This is doubtless incredibly basic, but it's typical of the stuff I'm tripping up on while adapting to OOP. Please don't be nasty.
Let's say that my main routine in my RunSea object instantiates an object of class Sea called atlantic.
Sea atlantic= new Sea();
(Earlier is the declaration: public Sea atlantic; I've tried having this in and out, and static present or not and it doesn't seem to make a difference.)
Within the Sea class, I instantiate an object of class Submarine called mySub.
There's actually an array of Submarine objects, but I'm assuming my problem applies to a single sub.
The Submarine class has a method called moveSub which wants to access a method in the atlantic object called checkMove. This determines whether a given location in altantic is free to move into.
The moveSub method in mySub can't access the atlantic object. The complier says "Cannot find symbol - variable atlantic". I can shut the compiler up by declaring one but (understandably) just get a null object pointer error at runtime.
The atlantic.checkMove method is public but I don't think that's the point. The mySub object can't see the atlantic object. I think.
Let's say that my main routine in my RunSea object instantiates an object of class Sea called atlantic.
Sea atlantic= new Sea();
(Earlier is the declaration: public Sea atlantic; I've tried having this in and out, and static present or not and it doesn't seem to make a difference.)
Within the Sea class, I instantiate an object of class Submarine called mySub.
There's actually an array of Submarine objects, but I'm assuming my problem applies to a single sub.
The Submarine class has a method called moveSub which wants to access a method in the atlantic object called checkMove. This determines whether a given location in altantic is free to move into.
The moveSub method in mySub can't access the atlantic object. The complier says "Cannot find symbol - variable atlantic". I can shut the compiler up by declaring one but (understandably) just get a null object pointer error at runtime.
The atlantic.checkMove method is public but I don't think that's the point. The mySub object can't see the atlantic object. I think.
Comment