Complete the code to declare a contract that inherits from another contract.
contract Base {
uint public value;
}
contract Derived is [1] {
}is.is keyword.The Derived contract inherits from Base using the is keyword followed by the base contract name.
Complete the code to call the base contract constructor with a value.
contract Base {
uint public value;
constructor(uint _value) {
value = _value;
}
}
contract Derived is Base {
constructor() Base([1]) {}
}The derived contract constructor calls the base constructor with a specific value, here 10.
Fix the error in the code by completing the inheritance syntax correctly.
contract A {
function greet() public pure returns (string memory) {
return "Hello from A";
}
}
contract B [1] A {
}extends or inherits which are not valid in Solidity.In Solidity, the correct keyword to inherit from a contract is is.
Fill both blanks to override a function from the base contract in the derived contract.
contract Base {
function greet() public pure virtual returns (string memory) {
return "Hello from Base";
}
}
contract Derived is Base {
function greet() public pure override returns (string memory) {
return [1];
}
}
// Use the function to get the greeting message
// string memory message = [2];The derived contract overrides the greet function to return a new message. The call to Derived().greet() returns the overridden message.
Fill all three blanks to create a contract that inherits from two contracts and calls both base constructors.
contract A {
uint public a;
constructor(uint _a) {
a = _a;
}
}
contract B {
uint public b;
constructor(uint _b) {
b = _b;
}
}
contract C is [1], [2] {
constructor() A(1) [3](2) {}
}Contract C inherits from A and B. The constructor calls both base constructors with values 1 and 2 respectively.