'类的概念(1)
Module Module1
Sub Main()
End Sub
Public Class Car
'成员变量
Private _Color As String = "红色" '车身颜色
Private _WheelCount As Short = 4 '轮胎数
Private _ChairCount As Short = 5 '座椅数
Private _RunCount As Integer = 0 '行驶公里数
Private _RunAble As Boolean = True '可行驶状态
'属性:颜色
Public Property Color() As String
Get
Return _Color '返回属性值
End Get
Set(ByVal Value As String)
_Color = Value '属性赋值
End Set
End Property
'轮子的数目
Public ReadOnly Property WheelCount() As Short
Get
Return _WheelCount
End Get
End Property
'座椅的数目
Public Property ChairCount() As Short
Get
Return _ChairCount
End Get
Set(ByVal Value As Short)
_ChairCount = Value
End Set
End Property
'已行驶公里数
Public Property RunCount() As Integer
Get
Return _RunCount
End Get
Set(ByVal Value As Integer)
_RunCount = Value
End Set
End Property
'可行驶状态
Public Property RunAble() As Boolean
Get
Return _RunAble
End Get
Set(ByVal Value As Boolean)
_RunAble = Value
End Set
End Property
'方法:汽车开动
Public Sub Go()
Console.WriteLine("嘀嘀嘀... ...")
End Sub
'构造方法
Sub New()
_Color = "米色"
End Sub
End Class
End Module