0
0
Blockchain / Solidityprogramming~5 mins

Abstract contracts in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an abstract contract in blockchain programming?
An abstract contract is a contract that cannot be deployed on its own because it has at least one function without implementation. It serves as a base for other contracts to inherit and implement missing functions.
Click to reveal answer
beginner
Why do we use abstract contracts?
We use abstract contracts to define common interfaces and shared behavior for multiple contracts. They help organize code and enforce that child contracts implement required functions.
Click to reveal answer
beginner
How do you declare an abstract contract in Solidity?
You declare an abstract contract by using the keyword <code>abstract</code> before <code>contract</code>. For example: <pre>abstract contract MyBase { function doSomething() public virtual; }</pre>
Click to reveal answer
intermediate
What happens if a contract inherits an abstract contract but does not implement all its functions?
The inheriting contract also becomes abstract and cannot be deployed until it implements all the abstract functions from its base contracts.
Click to reveal answer
intermediate
Can abstract contracts have implemented functions?
Yes, abstract contracts can have both implemented and unimplemented (abstract) functions. The unimplemented functions must be implemented by child contracts.
Click to reveal answer
What keyword is used to declare an abstract contract in Solidity?
Ainterface
Bvirtual
Cabstract
Doverride
Can you deploy an abstract contract directly?
AYes, always
BNo, never
COnly if all functions are implemented
DOnly if it has no functions
If a contract inherits an abstract contract but does not implement all abstract functions, what happens?
AIt becomes abstract and cannot be deployed
BIt deploys but throws errors at runtime
CIt automatically implements missing functions
DIt ignores the abstract functions
Which of these is true about abstract contracts?
AThey must be deployed before use
BThey cannot have any implemented functions
CThey are the same as interfaces
DThey can have both implemented and unimplemented functions
Why use abstract contracts instead of interfaces?
ATo share code and define some implemented functions
BBecause interfaces cannot be inherited
CBecause abstract contracts are cheaper to deploy
DBecause interfaces do not support functions
Explain what an abstract contract is and why it is useful in blockchain programming.
Think about contracts that set rules but don’t do everything themselves.
You got /4 concepts.
    Describe how inheritance works with abstract contracts and what happens if child contracts don’t implement all abstract functions.
    Consider what happens if you inherit a contract with missing pieces.
    You got /4 concepts.