I am playing with abstract classes and interfaces and in my sample program I
can't understand why I can't access a variable that is in the inherited
class. It is public and I thought that you could directly access
(apparently not).
*************** *************** *******
Option Strict On
Module Module1
Public Interface Plane
Property TailNumber() As String
Property NumberOfEngines () As Integer
End Interface
Public Class SingleEngineLan d
Implements Plane
Private FTailNumber As String
Public Engines As Integer = 1
Public Function NumberOfWheels( ) As Integer
Return 3
End Function
Public Property TailNumber() As String Implements Plane.TailNumbe r
Get
Return FTailNumber
End Get
Set(ByVal Value As String)
FTailNumber = Value
End Set
End Property
Public Property NumberOfEngines () As Integer Implements
Plane.NumberOfE ngines
Get
Return Engines
End Get
Set(ByVal Value As Integer)
Engines = Value
End Set
End Property
End Class
Public Class DoubleEngineLan d
Inherits SingleEngineLan d
Engines = 2 <--- The error
End Class
Sub Main()
Dim myPlane As New SingleEngineLan d
Dim myPlane2 As New SingleEngineLan d
Dim myPlane3 As New DoubleEngineLan d
myPlane.TailNum ber = "150"
myPlane2.TailNu mber = "2000"
Console.WriteLi ne(String.Forma t("My 1st Planes Tail Number is: {0}",
myPlane.TailNum ber))
Console.WriteLi ne(String.Forma t("My 2nd Planes Tail Number is: {0}",
myPlane2.TailNu mber))
Console.WriteLi ne(String.Forma t("My 1st Planes Number Wheels is
{0}", myPlane2.Number OfWheels))
Console.WriteLi ne(String.Forma t("My 3rd Planes TailNumber is {0}",
myPlane3.TailNu mber))
Console.WriteLi ne(String.Forma t("Number of engines in doubleEngine
Plane is {0}", myPlane3.Number OfEngines))
Console.Read()
End Sub
End Module
*************** *************** *******
What Do I have to do to access it.
I have Set up my SingleEnginePla ne Class to be the default class and set
"Engine=1". I then create another class "DoubleEnginePl ane" where I want to
change the variable "Engine=2", but I get the error:
Declaration expected
Shouldn't it be able to access the variable in the Base Class directly?
Thanks,
Tom
can't understand why I can't access a variable that is in the inherited
class. It is public and I thought that you could directly access
(apparently not).
*************** *************** *******
Option Strict On
Module Module1
Public Interface Plane
Property TailNumber() As String
Property NumberOfEngines () As Integer
End Interface
Public Class SingleEngineLan d
Implements Plane
Private FTailNumber As String
Public Engines As Integer = 1
Public Function NumberOfWheels( ) As Integer
Return 3
End Function
Public Property TailNumber() As String Implements Plane.TailNumbe r
Get
Return FTailNumber
End Get
Set(ByVal Value As String)
FTailNumber = Value
End Set
End Property
Public Property NumberOfEngines () As Integer Implements
Plane.NumberOfE ngines
Get
Return Engines
End Get
Set(ByVal Value As Integer)
Engines = Value
End Set
End Property
End Class
Public Class DoubleEngineLan d
Inherits SingleEngineLan d
Engines = 2 <--- The error
End Class
Sub Main()
Dim myPlane As New SingleEngineLan d
Dim myPlane2 As New SingleEngineLan d
Dim myPlane3 As New DoubleEngineLan d
myPlane.TailNum ber = "150"
myPlane2.TailNu mber = "2000"
Console.WriteLi ne(String.Forma t("My 1st Planes Tail Number is: {0}",
myPlane.TailNum ber))
Console.WriteLi ne(String.Forma t("My 2nd Planes Tail Number is: {0}",
myPlane2.TailNu mber))
Console.WriteLi ne(String.Forma t("My 1st Planes Number Wheels is
{0}", myPlane2.Number OfWheels))
Console.WriteLi ne(String.Forma t("My 3rd Planes TailNumber is {0}",
myPlane3.TailNu mber))
Console.WriteLi ne(String.Forma t("Number of engines in doubleEngine
Plane is {0}", myPlane3.Number OfEngines))
Console.Read()
End Sub
End Module
*************** *************** *******
What Do I have to do to access it.
I have Set up my SingleEnginePla ne Class to be the default class and set
"Engine=1". I then create another class "DoubleEnginePl ane" where I want to
change the variable "Engine=2", but I get the error:
Declaration expected
Shouldn't it be able to access the variable in the Base Class directly?
Thanks,
Tom
Comment