Features of contracts
Now it's time to get deeper into contracts. We will look at some new features and also get deeper into the features we have already seen.
Visibility
The visibility of a state variable or a function defines who can see it. There are four kinds of visibilities for function and state variables: external
, public
, internal
, and private
.
By default, the visibility of functions is public
and the visibility of state variables is internal
. Let's look at what each of these visibility functions mean:
external
: External functions can be called only from other contracts or via transactions. An external functionf
cannot be called internally; that is,f()
will not work, butthis.f()
works. You cannot apply theexternal
visibility to state variables.public
: Public functions and state variables can be accessed in all ways possible. The compiler generated accessor functions are all public state variables. You cannot create your own accessors. Actually, it generates only getters, not setters...