ClassCircle
PublicR
PrivateMArea
Public SubInit (a)
R=a
End Sub
Public FunctionArea ()
IfMarea="" Then
Marea=Atn(1)*4*r*r
End If
Area=marea
End Function
Private SubEchoinfo ()
MsgBox "The radius of the circle is:"& R &vbCrLf&"The area of the circle is:"& MArea
End Sub
End Class
Setc =NewCircle' Create a TestClass instance.
C.init2
' Init is the constructor name in Python, you can define other names as you like
' other languages, such as c#,c++, use the class name as the constructor name, and obviously no init is easy to remember .
MsgBoxC.r
MsgBoxC.area ()
' MsgBox C.marea
' cannot be accessed because this field is private and can only be accessed within the class, such as the area method above
' MsgBox c.echoinfo ()
' cannot be accessed because this method is private and can only be accessed within the class
Setc = Nothing ' Delete instance
Vbs:class, Public, Private