I have not found a proper way to do this. Let’s say Class Aa inherits from Class A.
My idea was to have two attributes overriden in Aa, so I could use these attribute in a function from A, when this function is being called from A.
Class A {
String attr;
public void publicMethod(){
....
callMethod2();
....
}
protected method2(){
....
whatever = attr;
}
}
Class Aa extends A{
//mandatory override?
attr
}
Calling example:
Aa test = new Aa();
test.publicMethod();
I think I could just “not make it mandatory” and it would work, but then it is not intuitive that you have to set up somehow this attribute.
Any workaround? I’m probably overengineering this.
You need the abstract keyword. However, it works only with methods, not with properties (which anyway is the proper way to do it).