I’m having a hard time finding what I need, and figuring out how to ask for it so please consider this:
public class Environment {
int x = 0;
int y = 0;
Operations op = new Operations();
public Environment(){
Operations.changeSuper();
}
}
and:
public class Operations extends Environment {
public void changeSuper(){
x++;
y--;
}
}
This is a simple representation of what I have attempted already. However I dont think that initializing Operations in Environment correct, as it causes the constructor to loop. But if I dont, then I get null pointer when I attempt to call changeSuper().
Is this the correct way to use extends? Whould there be a better way to abstract the methods from the class file.
Long story short, I want to move methods out of a class file, but still allow them to affect it’s local variables
Environmentisn’t anOperations.. so no.Sounds like you need composition. And you should make your class
OperationnotOperations.So have something like so:
and:
If the changes is done only in
Environment, then it makes maintaining easier, also preserving encapsulation.