Hi,
When extending a class, I can override a protected function of the base class, and other functions of the base class will then use the function from my derived class.
class TestSlave extends TestMaster {
protected function printInternal() {
System.println( "Slave" );
}
public function initialize() {
TestMaster.initialize();
}
}
class TestMaster {
protected function printInternal() {
System.println( "Master" );
}
public function print() {
printInternal();
}
}
However this seems to work only for functions. For member variables, I have to declare them public for this to work, like in the example below. If I'd declare _text as protected in this example, the compiler will tell me "Attempting to override protected variable from a parent class.".
class TestSlave extends TestMaster {
var _text = "Slave";
public function initialize() {
TestMaster.initialize();
}
}
class TestMaster {
var _text = "Master";
public function print() {
System.println( _text );
}
}
Is there any sense behind this difference between functions and variables? Can I achieve this for a variable without making it public?