a setter for @size (Write-Only) attr_accessor :color # Generates both a getter and setter for @color (Read/Write) def initialize @color = 0 # Within the object, we can access the instance variable directly @brand = "Penbrand" @size = 0.7 # But we could also use the setter method defined by the attr_accessor Class instance method end end pen = Pen.new puts pen.brand # Accesses the pen brand through the generated getter pen.size = 0.5 # Updates the size field of the pen through the generated setter pen.color = ~pen.color Visual Basic Visual Basic (.NET 2003–2010) Public Class Pen Private _color As Integer ' Private field Public Property Color() As Integer ' Public property Get Return _color End Get Set(ByVal value As Integer) _color = value End Set End Property End Class ' Create Pen class instance Dim pen As New Pen() ' Set value pen.Color = 1 ' Get value Dim color As Int32 = pen.Color Visual Basic (only .NET 2010) Public Class Pen Public Property Color() As Integer ' Public property End Class ' Create Pen class instance Dim pen As New Pen() ' Set value pen.Color = 1 ' Get value Dim color As Int32 = pen.Color Visual Basic 6 ' in a class named clsPen Private m_Color As Long Public Property Get Color() As Long Color = m_Color End Property Public Property Let Color(ByVal RHS As Long) m_Color = RHS End Property ' accessing: Dim pen As New clsPen ' ... pen.Color = Not pen.Color See also Attribute (computing) Bound property Field (computer science) Indexer (programming) Method (computer programming) Mutator method Uniform access principle References Object-oriented programming Articles with example PHP code Articles with example Python (programming language) code Articles with example Ruby code