I was editing and trying out the code from https://solidity-by-example.org/shadowing-inherited-state-variables and got the following output.
pragma solidity >=0.8.0 <0.9.0;
//SPDX-License-Identifier: MIT
contract Parent {
string public name = "Contract Parent";
}
contract Child is Parent {
constructor() {
name = "Contract Child";
}
function getName() public view returns (string memory) {
return name;
}
string public childGetName = getName();
}
OUTPUT
childGetName
"Contract Parent"
getName
"Contract Child"
name
"Contract Child"
I want to know why childGetName is not "Contract Child" since the inherited state variable (name) has been overridden.
Thank you