Let's assume I have the following two contracts Hello and Goodbye, and Goodbye inherits from Hello. Both declare a constant variable aString, i.e. the child contract Goodbye overwrites the parent's value:
pragma solidity ^0.4.17;
contract Hello {
// This will be overwritten by child
string public constant aString = 'Hello World!';
// Prints Hello World
function printMe() returns (string){
return aString;
}
}
contract Goodbye is Hello{
// Overwrites `aString` of parent
string public constant aString = 'Goodbye World!';
// Why does this print Hello World, too???
function printMe() returns (string){
return super.printMe();
}
// Prints Goodbye World as expected
function printMe2() returns (string){
return aString;
}
}
So if I call printMe() of contract Hello it returns 'Hello World!' as expected.
Moreover, if I create the contract Goodbye and call its function printMe2() it returns 'Goodbye World!' because aString overwrites the parent's definition of 'Hello World!'. However, if call printMe() of Goodbye which, in turn, calls super.printMe() it returns 'Hello World!'?
Why does printMe() in Goodbye not return 'Goodbye World!'? Why is the overwriting of aString by Goodbye ignored by the super.printMet() call?