An Overloaded Class - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

An Overloaded Class

Description:

Public Property Conveyance() Get. Return strConveyance. End Get. Set ... Conveyance could be car or truck. The Car Class and Truck Class. Public Class Truck ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 8
Provided by: davidlk2
Category:

less

Transcript and Presenter's Notes

Title: An Overloaded Class


1
An Overloaded Class
  • Polymorphism

Illustrative Program Code
2
Define a Vehicle Class
First declare all of the variables needed by this
class
Public Class Vehicle Public intWheels
As Integer Public strManufacturer As
String Public strYear As String
Public strCondition As String
3
The Default Constructor
Sub New(ByVal intWheels As Integer)
strManufacturer "" strYear
"" strCondition "" End Sub
This constructor looks forward to inheriting into
children classes each having a specific number of
wheels. Initialize the other variables to any
desired value. Constructor arbitration will not
be an issue here because there is only one
constructor.
4
The FourWheeler Class
Sub New(ByVal strConveyance As String)
MyBase.New(4) Conveyance strConveyance
End Sub Public Property Conveyance()
Get Return strConveyance End
Get Set(ByVal Value)
strConveyance Value End Set End
Property End Class
Wheels defaults to 4
This property is unique to the FourWheeler Class.
Conveyance could be car or truck.
5
The Car Class and Truck Class
Public Class Truck Inherits FourWheeler
Sub New() MyBase.New("Truck") End
SubEnd Class Public Class Car Inherits
FourWheeler Sub New()
MyBase.New("Car") End Sub End Class
The Conveyance Property defaults to Truck
The Conveyance Property defaults to Car
6
The Bike Class
Public Class Bike Inherits Vehicle
Public boolSideCar As Boolean False Public
strClassification As String Sub New(ByVal
strClassification As String, ByVal boolSideCar As
Boolean) MyBase.New(2)
Classification strClassification End Sub

The Wheels property will default to 2
The SideCar and Classification property methods
must also be included.
7
The Hog and DirtBike classes
Public Class Dirt Inherits Bike Sub
New() MyBase.New("Dirt bike", False)
End Sub End Class
Public Class Hog Inherits Bike Sub New()
MyBase.New("Hog", False) End SubEnd
Class
Write a Comment
User Comments (0)
About PowerShow.com