0
0
Blockchain / Solidityprogramming~20 mins

Why inheritance promotes code reuse in Blockchain / Solidity - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Inheritance Mastery in Blockchain
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Solidity inheritance example
What is the output of this Solidity contract when calling getMessage() from contract Child?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract Parent {
    function getMessage() public pure virtual returns (string memory) {
        return "Hello from Parent";
    }
}

contract Child is Parent {
    function getMessage() public pure override returns (string memory) {
        return "Hello from Child";
    }
}
A"Hello from Child"
BRuntime error due to inheritance conflict
CCompilation error due to missing override
D"Hello from Parent"
Attempts:
2 left
💡 Hint
Look at which function is called in the Child contract and how override works.
🧠 Conceptual
intermediate
1:30remaining
Why inheritance helps code reuse in smart contracts
Which of the following best explains why inheritance promotes code reuse in blockchain smart contracts?
AIt prevents contracts from calling functions of other contracts.
BIt forces contracts to duplicate code for security reasons.
CIt allows contracts to share and extend existing code without rewriting it.
DIt makes contracts run faster by removing all function calls.
Attempts:
2 left
💡 Hint
Think about how inheritance lets you build on top of existing code.
🔧 Debug
advanced
2:00remaining
Identify the error in Solidity inheritance
What error will this Solidity code produce?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract Base {
    function greet() public pure returns (string memory) {
        return "Hi";
    }
}

contract Derived is Base {
    function greet() public pure returns (string memory) {
        return "Hello";
    }
}
ACompilation error: Function must be marked override in Derived
BNo error, code compiles and greet returns "Hello"
CRuntime error: greet function not found
DCompilation error: Missing virtual keyword in Base
Attempts:
2 left
💡 Hint
Check if the override keyword is used correctly when redefining functions.
📝 Syntax
advanced
1:30remaining
Correct syntax for multiple inheritance in Solidity
Which option shows the correct syntax for a contract inheriting from two contracts A and B in Solidity?
Acontract C is A, B {}
Bcontract C inherits A and B {}
Ccontract C : A, B {}
Dcontract C extends A, B {}
Attempts:
2 left
💡 Hint
Look at how Solidity uses the 'is' keyword for inheritance.
🚀 Application
expert
2:30remaining
How inheritance reduces gas costs in smart contracts
How does using inheritance in smart contracts help reduce gas costs during deployment and execution?
AInheritance disables expensive function calls to save gas.
BInheritance automatically compresses bytecode to half its size.
CIt allows contracts to run off-chain, saving gas.
DBy reusing code, contracts avoid duplicating logic, reducing contract size and gas fees.
Attempts:
2 left
💡 Hint
Think about how code reuse affects contract size and deployment cost.