Function Visibility Modifier vs State Variable Visibility Modifier

The main difference between the function and state variable visibility modifier is that there are four function visibility specifiers whereas three state variable visibility specifiers. The function visibility specifiers are public, private, internal, and external but state variable visibility specifiers are public, private, and internal only. If the state variable visibility specifier is public then it can be accessed by all the contracts, if private then the contract in which the state variable is declared can access it and if internal then the contract declared it and its child contract can access it.

Visibility Specifier Function State variable
Public All contracts can call the function with public visibility specifier. The State variable declared with the public visibility Specifier can be accessed by all the contracts.
Private Only the contract containing the function can call the function with visibility Specifier private. The State variables declared with private visibility Specifier can only be used by the same contract in which it is declared.
Internal The contract containing the function and its child contracts can call the function with internal visibility Specifier. The State variable declared with internal visibility Specifier can be used by the same contract or its child contracts.
External The external contracts can call the function with external visibility Specifier. The state variable does not have external visibility Specifier.
Default visibility Specifier  The default visibility Specifier for functions is public in Solidity. The default visibility Specifier for the State variable is internal in Solidity.


Function Visibility Specifier in Solidity

Function in Solidity is a set of code that performs a specific task. The function provides reusability of code in smart contracts. In Solidity, functions are defined using the function keyword. The syntax of the function definition in Solidity is:

function function_name (parameter list) visibilty_specifier modifier returns (return_type)
{
   Block of Code
}

Function visibility in Solidity defines the visibility of the function to other functions within the contract, or in other contracts. Function visibility helps to identify where in the contract or in other contracts, functions can be used. It is specified by the developer of the smart contract. The default variable visibility in Solidity is internal. The default function visibility in Solidity is public.  

Similar Reads

How do Function Visibility Modifiers and Inheritance Work Together?

Inheritance is the property in which the child contract uses the features of the parent contract. In Solidity, the keyword ‘is’ is used to provide inheritance. The function visibility is set in the parent contract according to which the child contract can use its parent’s function. The function visibility of the function provides the accessibility of the function to the child contract. The visibility defined in the parent contract is used to identify whether the child contract can use the function or not or if it is private to the parent contract only....

Function Visibility Modifiers

...

Function Visibility Modifier vs State Variable Visibility Modifier

The function visibility specifier helps in specifying the type of visibility of the function. It is like access specifiers in other OOP languages such as C++. The function visibility specifiers define the visibility of the function within the entire smart contract. There are four function visibility specifiers in Solidity: public, internal, external, and private....