State variables are variables whose values are permanently stored in contract storage.
visibility
總共三種: public
, private
, internal
public
- 變數資料儲存於 storage region 中,compiler 會為其分配 storage slot
- 當合約被繼承時,依舊可以被繼承的合約使用
- compiler 會自動為變數建立 getter function,可以外部存取
internal
- 變數資料儲存於 storage region 中,compiler 會為其分配 storage slot
- 當合約被繼承時,依舊可以被繼承的合約使用
private
- 變數資料儲存於 storage region 中,compiler 會為其分配 storage slot