0
0
Blockchain / Solidityprogramming~10 mins

Multiple inheritance in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a contract that inherits from two contracts.

Blockchain / Solidity
contract MyContract is [1], ContractB {}
Drag options to blanks, or click blank then click option'
AContractC
BMyContract
CBaseContract
DContractA
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to list the first parent contract.
Using the child contract name instead of a parent contract.
2fill in blank
medium

Complete the code to call the constructor of the first parent contract.

Blockchain / Solidity
contract MyContract is ContractA, ContractB {
    constructor() [1]() {}
}
Drag options to blanks, or click blank then click option'
AContractA
Boverride
Csuper
Dpublic
Attempts:
3 left
💡 Hint
Common Mistakes
Using super instead of the parent contract's name.
Omitting the parentheses after the contract name.
3fill in blank
hard

Fix the error in the function override declaration for multiple inheritance.

Blockchain / Solidity
function foo() public view virtual override([1]) returns (string memory) {
    return "Hello";
}
Drag options to blanks, or click blank then click option'
AContractB
BContractA, ContractB
CContractA
DMyContract
Attempts:
3 left
💡 Hint
Common Mistakes
Listing only one parent contract in the override.
Using the child contract name in the override list.
4fill in blank
hard

Fill both blanks to define a contract that inherits and overrides a function from two parents.

Blockchain / Solidity
contract MyContract is [1], [2] {
    function foo() public view virtual override(ContractA, ContractB) returns (string memory) {
        return "Hello from MyContract";
    }
}
Drag options to blanks, or click blank then click option'
AContractA
BMyContract
CContractB
DBaseContract
Attempts:
3 left
💡 Hint
Common Mistakes
Using the child contract name in the inheritance list.
Forgetting to list both parent contracts.
5fill in blank
hard

Fill all three blanks to create a mapping with keys from one contract and values from another.

Blockchain / Solidity
mapping([1] => [2]) public data;

function setData([3] key, uint value) public {
    data[key] = value;
}
Drag options to blanks, or click blank then click option'
Aaddress
Buint
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using mismatched types for mapping keys and function parameters.
Using string instead of address for keys.