Complete the code to inherit properties from the parent contract.
contract Child is [1] {
// Child contract code
}The child contract inherits from the Parent contract to reuse its code.
Complete the code to call the parent constructor in the child contract.
contract Child is Parent {
constructor() [1] {
Parent();
// Initialization
}
}The child constructor must be public to call the parent's constructor properly.
Fix the error in overriding the parent function in the child contract.
contract Child is Parent {
function greet() [1] override returns (string memory) {
return "Hello from Child!";
}
}The function visibility must be public to correctly override the parent's function.
Fill both blanks to define a function in the parent contract that can be overridden by the child.
contract Parent {
function greet() public [1] returns (string memory) {
return "Hello from Parent!";
}
}
contract Child is Parent {
function greet() public [2] returns (string memory) {
return "Hello from Child!";
}
}The parent function must be marked virtual to allow overriding, and the child function must use override.
Fill all three blanks to create a reusable modifier in the parent and apply it in the child contract.
contract Parent {
modifier onlyOwner() [1] {
require(msg.sender == owner, "Not owner");
_;
}
}
contract Child is Parent {
function secureAction() [2] [3] onlyOwner {
// secure code
}
}The modifier is usually internal. The child function is public and uses override if it overrides a parent function.