T
tshad
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 SingleEngineLand
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.TailNumber
Get
Return FTailNumber
End Get
Set(ByVal Value As String)
FTailNumber = Value
End Set
End Property
Public Property NumberOfEngines() As Integer Implements
Plane.NumberOfEngines
Get
Return Engines
End Get
Set(ByVal Value As Integer)
Engines = Value
End Set
End Property
End Class
Public Class DoubleEngineLand
Inherits SingleEngineLand
Engines = 2 <--- The error
End Class
Sub Main()
Dim myPlane As New SingleEngineLand
Dim myPlane2 As New SingleEngineLand
Dim myPlane3 As New DoubleEngineLand
myPlane.TailNumber = "150"
myPlane2.TailNumber = "2000"
Console.WriteLine(String.Format("My 1st Planes Tail Number is: {0}",
myPlane.TailNumber))
Console.WriteLine(String.Format("My 2nd Planes Tail Number is: {0}",
myPlane2.TailNumber))
Console.WriteLine(String.Format("My 1st Planes Number Wheels is
{0}", myPlane2.NumberOfWheels))
Console.WriteLine(String.Format("My 3rd Planes TailNumber is {0}",
myPlane3.TailNumber))
Console.WriteLine(String.Format("Number of engines in doubleEngine
Plane is {0}", myPlane3.NumberOfEngines))
Console.Read()
End Sub
End Module
*************************************
What Do I have to do to access it.
I have Set up my SingleEnginePlane Class to be the default class and set
"Engine=1". I then create another class "DoubleEnginePlane" 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 SingleEngineLand
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.TailNumber
Get
Return FTailNumber
End Get
Set(ByVal Value As String)
FTailNumber = Value
End Set
End Property
Public Property NumberOfEngines() As Integer Implements
Plane.NumberOfEngines
Get
Return Engines
End Get
Set(ByVal Value As Integer)
Engines = Value
End Set
End Property
End Class
Public Class DoubleEngineLand
Inherits SingleEngineLand
Engines = 2 <--- The error
End Class
Sub Main()
Dim myPlane As New SingleEngineLand
Dim myPlane2 As New SingleEngineLand
Dim myPlane3 As New DoubleEngineLand
myPlane.TailNumber = "150"
myPlane2.TailNumber = "2000"
Console.WriteLine(String.Format("My 1st Planes Tail Number is: {0}",
myPlane.TailNumber))
Console.WriteLine(String.Format("My 2nd Planes Tail Number is: {0}",
myPlane2.TailNumber))
Console.WriteLine(String.Format("My 1st Planes Number Wheels is
{0}", myPlane2.NumberOfWheels))
Console.WriteLine(String.Format("My 3rd Planes TailNumber is {0}",
myPlane3.TailNumber))
Console.WriteLine(String.Format("Number of engines in doubleEngine
Plane is {0}", myPlane3.NumberOfEngines))
Console.Read()
End Sub
End Module
*************************************
What Do I have to do to access it.
I have Set up my SingleEnginePlane Class to be the default class and set
"Engine=1". I then create another class "DoubleEnginePlane" 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