allelopath
asked on
Override method problem - StackOverflowError
I have classes like so:
I want to override the method so that I can do some things not in the parent class method, but first I have to make sure that myObject gets set. As it is, this code gives a StackOverflowError because ChildClass.setMyObject() is called ad infinitum. I cannot change the access of myObject to protected. How is this done?
public class ParentClass {
private Object myObject;
public void setMyObject(final Object object) {
this.myObject = object
}
}
public class ChildClass extends ParentClass {
@Override
public void setMyObject(final Object object) {
setMyObject(object);
// do other stuff
}
}
I want to override the method so that I can do some things not in the parent class method, but first I have to make sure that myObject gets set. As it is, this code gives a StackOverflowError because ChildClass.setMyObject() is called ad infinitum. I cannot change the access of myObject to protected. How is this done?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
have a look here: http://docs.oracle.com/javase/tutorial/java/IandI/super.html