一个关于继承问题
Public MustInherit Class animal
'名字
Public name As String
'可由子类从新定义的方法
Public Overridable Sub shout()
System.Console.WriteLine("某种动物在叫")
End Sub
End Class
Public Class dog
Inherits animal
Public Overrides Sub shout()
System.Console.WriteLine("汪汪。。。,我叫{0},我会看门,同时兼职抓耗子以赚点钱", name)
End Sub
Public Class cat
Inherits animal
Public Overrides Sub shout()
System.Console.WriteLine("喵喵。。。。,我叫{0},只要会讨好主人,吃穿不愁", name)
End Sub
End Class
End Class
Module Module1
Sub Main()
'创建一只狗,起名”威虎”
Dim d As New dog
d.name = "威虎"
d.shout() '狗在做自我介绍
'创建一只猫,起名“小妙”
Dim c As New dog.cat
c.name = "小妙"
c.shout() '猫在做自我介绍
Dim a As animal
a = d
a.shout()
a = c
a.shout()
'暂停
System.Console.ReadLine()
End Sub
End Module
上为什么Dim c As New dog.cat不能直接用Dim c As New cat呢?