在工程中创建3个Class Module,名字分别为:Animal、Cat、Dog:
Animal是接口:Sub Cry()
End Sub
Cat和Dog类是实现:
Implements Animal
Private Sub Animal_Cry() MsgBox "miao miao"End Sub
Implements Animal
Private Sub Animal_Cry() MsgBox "wang wang"End Sub
然后调用的代码如下:Private Sub Command1_Click() Dim a1 As Animal Dim a2 As Animal Set a1 = New Dog Set a2 = New Cat a1.Cry a2.CryEnd Sub