我是VB.net的新手,我无法编译这段代码,我不明白为什么。
MustInherit Class Poligono
Protected p_cant_Lados As Integer
Public Property cant_Lados() As Integer
Get
Return p_cant_Lados
End Get
Set(ByVal value As Integer)
p_cant_Lados = value
End Set
End Property
Public MustOverride Function obtenerPerimetro()
Public MustOverride Function cargarLados()
End Class
Public Class Triangulo
Inherits Poligono
Private lado1 As Integer
Private lado2 As Integer
Private lado3 As Integer
Public Function cargarLados() As Object
Return 1
End Function
Public Function obtenerPerimetro() As Object
Return 1
End Function
End Class
错误2'Triangulo'不能继承“Poligono”类,因为它 扩展基类的访问权限 部件。 c:\ users \ win7 \ documents \ visual studio 2013 \ Projects \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 33 14 WindowsApplication1
谢谢!
答案 0 :(得分:7)
默认情况下,classes declared at the namespace level get Friend
access level。因此Poligono
是Friend Class
。一般公众可能无法看到Friend
课程。
更改
MustInherit Class Poligono
到
Public MustInherit Class Poligono
答案 1 :(得分:3)
两件事:
您必须使用As
Public MustOverride Function obtenerPerimetro() As Object
Public MustOverride Function cargarLados() As Object
您必须将Overrides
添加到覆盖抽象基类的方法
Public Overrides Function cargarLados() As Object
Return 1
End Function
Public Overrides Function obtenerPerimetro() As Object
Return 1
End Function