Advertisement
Roy11I

Inheritance

Feb 5th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.20 KB | None | 0 0
  1. Class Vehicle
  2.  
  3.     Private Colour As String
  4.     Private Windows As String
  5.     Private Doors As Integer
  6.     Private Engine As String
  7.  
  8.     Public Sub SetColour(ByVal c As String)
  9.         Colour = c
  10.     End Sub
  11.  
  12.     Public Sub SetWindows(ByVal w As String)
  13.         Windows = w
  14.     End Sub
  15.  
  16.     Public Sub SetDoors(ByVal d As Integer)
  17.         Doors = d
  18.     End Sub
  19.  
  20.     Public Sub SetEngine(ByVal e As String)
  21.         Engine = e
  22.     End Sub
  23.  
  24.     Public Function GetColour() As String
  25.         Return (Colour)
  26.     End Function
  27.  
  28.     Public Function GetWindows() As String
  29.         Return (Windows)
  30.     End Function
  31.  
  32.     Public Function GetDoors() As Integer
  33.         Return (Doors)
  34.     End Function
  35.  
  36.     Public Function GetEngine() As String
  37.         Return (Engine)
  38.     End Function
  39.  
  40. End Class
  41.  
  42. Class Car
  43.     Inherits Vehicle
  44.  
  45.     Private Trunk As String
  46.     Private Model As String
  47.  
  48.     Public Sub SetTrunk(ByVal t As String)
  49.         Trunk = t
  50.     End Sub
  51.  
  52.     Public Sub SetModel(ByVal m As String)
  53.         Model = m
  54.     End Sub
  55.  
  56.     Public Function GetTrunk() As String
  57.         Return (Trunk)
  58.     End Function
  59.  
  60.     Public Function GetModel() As String
  61.         Return (Model)
  62.     End Function
  63.  
  64. End Class
  65.  
  66. Class Truck
  67.     Inherits Vehicle
  68.  
  69.     Private Off_Road As String
  70.     Private Bed_Type As String
  71.  
  72.     Public Sub SetOff_Road(ByVal r As String)
  73.         Off_Road = r
  74.     End Sub
  75.  
  76.     Public Sub SetBed_Type(ByVal b As String)
  77.         Bed_Type = b
  78.     End Sub
  79.  
  80.     Public Function GetOff_Road()
  81.         Return (Off_Road)
  82.     End Function
  83.  
  84.     Public Function GetBed_Type()
  85.         Return (Bed_Type)
  86.     End Function
  87.  
  88. End Class
  89.  
  90. Module Module1
  91.  
  92.     Sub Main()
  93.  
  94.         Dim TestCar As New Car
  95.         Dim TestTruck As New Truck
  96.  
  97.         TestCar.SetColour("Blue")
  98.         TestCar.SetWindows("Power Windows")
  99.         TestCar.SetDoors(4)
  100.         TestCar.SetEngine("V6")
  101.         TestCar.SetTrunk("Trunk")
  102.         TestCar.SetModel("Sedan")
  103.  
  104.         TestTruck.SetColour("Black")
  105.         TestTruck.SetWindows("Power Windows")
  106.         TestTruck.SetDoors(4)
  107.         TestTruck.SetEngine("V8")
  108.         TestTruck.SetOff_Road("Off Road")
  109.         TestTruck.SetBed_Type("Extended")
  110.  
  111.         Console.WriteLine("The car colour is " & TestCar.GetColour & ".")
  112.         Console.WriteLine("The car windows are " & TestCar.GetWindows & ".")
  113.         Console.WriteLine("The car has " & TestCar.GetDoors & " doors.")
  114.         Console.WriteLine("The car engine is " & TestCar.GetEngine & ".")
  115.         Console.WriteLine("The car trunk is a " & TestCar.GetTrunk & ".")
  116.         Console.WriteLine("The car model is a " & TestCar.GetModel & ".")
  117.         Console.WriteLine()
  118.         Console.WriteLine("The truck colour is " & TestTruck.GetColour & ".")
  119.         Console.WriteLine("The truck windows are " & TestTruck.GetWindows & ".")
  120.         Console.WriteLine("The truck has " & TestTruck.GetDoors & " doors.")
  121.         Console.WriteLine("The truck engine is " & TestTruck.GetEngine & ".")
  122.         Console.WriteLine("The truck off-road capability is a " & TestTruck.GetOff_Road & ".")
  123.         Console.WriteLine("The truck bed type is " & TestTruck.GetBed_Type & ".")
  124.  
  125.     End Sub
  126.  
  127. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement