Recall & Review
beginner
What does the virtual keyword do in a blockchain smart contract?
It marks a function that can be changed (overridden) by a contract that inherits from this one. Think of it like a placeholder that child contracts can customize.
Click to reveal answer
beginner
What is the purpose of the override keyword in a derived contract?
It tells the blockchain compiler that this function replaces a virtual function from a parent contract. It’s like saying, "I’m changing how this works here."
Click to reveal answer
intermediate
Can a function be overridden if it is not marked as
virtual in the parent contract?No. Only functions marked as
virtual can be overridden. This protects important functions from accidental changes.Click to reveal answer
intermediate
Why is it important to use
override explicitly when changing a function?It helps avoid mistakes by making sure you really mean to replace a parent function. The compiler checks this and gives an error if you forget it.
Click to reveal answer
beginner
Example: What happens if a child contract overrides a virtual function but forgets to use
override keyword?The compiler will give an error and won’t let the contract compile. This prevents accidental mistakes in your smart contract code.Click to reveal answer
What keyword must a parent contract use to allow a function to be changed by a child contract?
✗ Incorrect
The
virtual keyword marks a function as changeable by child contracts.Which keyword must a child contract use when it changes a parent's virtual function?
✗ Incorrect
The
override keyword tells the compiler you are replacing a parent's virtual function.What happens if you override a function but forget to use
override keyword?✗ Incorrect
The compiler requires
override to confirm you want to replace the parent's function.Can a function without
virtual be overridden?✗ Incorrect
Functions must be marked
virtual to be overridden.Why do blockchain languages require explicit
virtual and override keywords?✗ Incorrect
Explicit keywords help avoid mistakes by making function changes clear and checked by the compiler.
Explain in your own words how the
virtual and override keywords work together in blockchain smart contracts.Think about how a parent contract allows children to customize behavior safely.
You got /4 concepts.
Why is it important to mark functions as
virtual before allowing them to be overridden?Consider what could happen if any function could be changed without warning.
You got /4 concepts.