Challenge - 5 Problems
Inheritance Mastery in Blockchain
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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"; } }
Attempts:
2 left
💡 Hint
Look at which function is called in the Child contract and how override works.
✗ Incorrect
The Child contract overrides the getMessage function from Parent, so calling getMessage on Child returns "Hello from Child".
🧠 Conceptual
intermediate1:30remaining
Why inheritance helps code reuse in smart contracts
Which of the following best explains why inheritance promotes code reuse in blockchain smart contracts?
Attempts:
2 left
💡 Hint
Think about how inheritance lets you build on top of existing code.
✗ Incorrect
Inheritance allows a contract to reuse code from a parent contract, reducing duplication and making development easier.
🔧 Debug
advanced2: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"; } }
Attempts:
2 left
💡 Hint
Check if the override keyword is used correctly when redefining functions.
✗ Incorrect
No error, code compiles and greet returns "Hello". The function in Derived shadows the one in Base because the Base function is not marked virtual, so override is not required.
📝 Syntax
advanced1: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?Attempts:
2 left
💡 Hint
Look at how Solidity uses the 'is' keyword for inheritance.
✗ Incorrect
Solidity uses the 'is' keyword followed by comma-separated parent contracts to declare inheritance.
🚀 Application
expert2:30remaining
How inheritance reduces gas costs in smart contracts
How does using inheritance in smart contracts help reduce gas costs during deployment and execution?
Attempts:
2 left
💡 Hint
Think about how code reuse affects contract size and deployment cost.
✗ Incorrect
Reusing code through inheritance means less repeated code, which reduces contract size and lowers gas costs for deployment and execution.