0
0
Blockchain / Solidityprogramming~5 mins

Visibility modifiers (public, private, internal, external) in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the public visibility modifier mean in blockchain smart contracts?
A public function or variable can be accessed both internally within the contract and externally by other contracts or users.
Click to reveal answer
beginner
Explain the private visibility modifier.
A private function or variable is only accessible inside the contract where it is defined. It cannot be accessed by derived contracts or externally.
Click to reveal answer
intermediate
What is the difference between internal and private visibility?
Internal functions or variables can be accessed inside the contract and by contracts that inherit from it, while private ones are only accessible inside the defining contract.
Click to reveal answer
intermediate
When should you use the external visibility modifier?
External functions are meant to be called from other contracts or transactions, but not from within the same contract. They are efficient for functions called only externally.
Click to reveal answer
advanced
Can a public function call an external function internally?
No, a public function cannot call an external function internally using a simple function call. External functions require a message call (like a transaction). However, a public function can call an external function using this.<functionName>().
Click to reveal answer
Which visibility modifier allows access only within the contract it is defined in?
Aexternal
Bpublic
Cprivate
Dinternal
Which visibility modifier allows access from derived contracts?
Ainternal
Bprivate
Cexternal
Dpublic
Which visibility modifier is designed to be called only from outside the contract?
Ainternal
Bprivate
Cpublic
Dexternal
Can a public function be called from outside the contract?
AYes
BNo
COnly if inherited
DOnly if marked external
Which visibility modifier is the most restrictive?
Apublic
Bprivate
Cinternal
Dexternal
Describe the four visibility modifiers used in blockchain smart contracts and give a simple example of when to use each.
Think about who can call the function or access the variable.
You got /4 concepts.
    Explain why you might choose 'internal' over 'private' for a function in a smart contract.
    Consider contract inheritance and extending functionality.
    You got /3 concepts.