public class NewClass extends BaseClass {
public NewClass() {
}
//This is the Class that I want to override
protected class CreatorClass {
public NewClass created = new NewClass();
}
}
public class BaseClass {
BaseClass() {
}
public CreatorClass getCreator() {
return creator;
}
CreatorClass creator = new CreatorClass();
//This is the Class that I want other classes to override
protected class CreatorClass {
public BaseClass created = new BaseClass();
}
}
//And I want to be able to do like this:
BaseClass obj = NewClass();
//And a call to getCreator is supposed to return the
//new CreatorClass
obj.getCreator();
So, basically I want the BaseClass to use the CreatorClass in the NewClass. And I understand that I would need to bypass the Variable Shawoding somehow, to let the variable work similar to method overriding?
I would like to know if there is any way of achieving this?
Thank you!
[edited by - FxMazter on February 22, 2004 4:32:12 PM]
[edited by - FxMazter on February 22, 2004 5:45:34 PM]
[java] Inheriting variables with the same name? getting rid of Shadowing variables?
Hey guys!
If I have a super class that has a variable with the same name as a class inheriting from it, is there any way of telling the super class to use the inherited class's variable?
eg:
That code is awfully convoluted. I''m not sure what exactly you are trying to achieve. Can you explain the class hierarchy you are looking for a little better?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement