Base class and derived class
📖 Scenario: You are creating a simple program to represent vehicles. Each vehicle has a brand name. Cars are a special type of vehicle that also have a model name.
🎯 Goal: Build a base class called Vehicle with a brand field, then create a derived class called Car that adds a model field. Finally, display the brand and model of a car.
📋 What You'll Learn
Create a base class named
Vehicle with a public string field brandCreate a derived class named
Car that inherits from VehicleAdd a public string field
model to the Car classCreate an instance of
Car with brand "Toyota" and model "Corolla"Print the brand and model of the car in the format: "Brand: Toyota, Model: Corolla"
💡 Why This Matters
🌍 Real World
Understanding base and derived classes helps organize code when working with related objects, like different types of vehicles.
💼 Career
Inheritance is a key concept in object-oriented programming used in many software development jobs to create reusable and organized code.
Progress0 / 4 steps