A public
state variable will have an automatically generated accessor that other contracts can use to read the variable.
However, public state variables can only be changed by a function in a contract that changes the variable. If there are no such functions that are accessible to other contracts, the state variable cannot be changed by other contracts.
Functions can be specified as being external
, public
, internal
or private
, where the default is public
.
external: External functions are part of the contract interface, which
means they can be called from other contracts and via transactions. An
external function f cannot be called internally (i.e. f()
does not
work, but this.f()
works). External functions are sometimes more
efficient when they receive large arrays of data.
public: Public functions are part of the contract interface and can be
either called internally or via messages. For public state variables,
an automatic accessor function (see below) is generated.
internal: Those functions and state variables can only be accessed
internally (i.e. from within the current contract or contracts
deriving from it), without using this
.
private: Private functions and state variables are only visible for
the contract they are defined in and not in derived contracts.