class Vehicle // base class (parent)
{
public string brand = "Ford"; // Vehicle field
public void honk() // Vehicle method
{
Console.WriteLine("Tuut, tuut!");
}
}
class Car : Vehicle // derived class (child)
{
public string modelName = "Mustang"; // Car field
}
class Program
{
static void Main(string[] args)
{
// Create a myCar object
Car myCar = new Car();
// Call the honk() method (From the Vehicle class) on the myCar object
myCar.honk();
// Display the value of the brand field (from the Vehicle class) and the value of the modelName from the Car class
Console.WriteLine(myCar.brand + " " + myCar.modelName);
}
}
''Vehicle.Class
public brand as string = "Ford" ' Vehicle field
public Sub honk() ' Vehicle method
Print("Tuut, tuut!")
End sub
''Car.Class
Inherits Vehicle 'derived class (child)
public modelName as string = "Mustang" ' Car field
''Program.Class
Sub Main(args as string[] )
' Create a myCar object
Dim myCAr as Car
myCar = new Car
' Call the honk() method (From the Vehicle class) on the myCar object
myCar.honk()
' Display the value of the brand field (from the Vehicle class) and the value of the modelName from the Car class
Print (myCar.brand & " " & myCar.modelName)
End