Visibility modifiers define the visibility for both state variables and functions. Visibility modifiers determine whether or not you are able to access a variable or execute a function.
There are four visibility modifiers available in the Solidity programming language. They are:
Public functions and variables can be accessed by all parties within and outside the contract. When the visibility is not specified, the default visibility of a function is
If a variable is has
public visibility, the Solidity compiler automatically creates a getter function for accessing the value of the variable.
If you want a variable or function to be accessed from within the contract or from outside the contract, use
Private functions and variables are only accessible within the contract in which they were declared. Private functions are also the only functions that cannot be inherited by other functions.
You would think that if you mark a variable or function as private then it would not be visible on the blockchain. This is false. The variable and function are visible to observers of the blockchain. You are not able to access them from other contracts.
Private is the most restrictive of the four visibility modifiers.
Internal functions and variables are only accessible within the contract in which they were declared. Internal functions and variables can be accessed from derived contracts. They cannot be accessed from outside the contract.
Internal is the default visibility for state variables.
Only functions can have the external visibility modifier. External functions can only be called from outside the contract in which they were declared. They can't be called internally.