


What is a Subclass in Python?
A subclass is a class that inherits properties and methods from another class, called the superclass or parent class. The subclass inherits all the attributes and methods of the superclass and can also add its own attributes and methods.
For example, let's say we have a class called "Vehicle" that has attributes like "color" and "number_of_wheels" and methods like "drive" and "park". Now, we can create a subclass called "Car" that inherits from the Vehicle class and adds its own attributes and methods specific to cars. The Car class would inherit all the attributes and methods of the Vehicle class and could also add its own attributes and methods like "make" and "model".
Here is an example of how you might define a subclass in Python:
```
class Vehicle:
def __init__(self, color, number_of_wheels):
self.color = color
self.number_of_wheels = number_of_wheels
def drive(self):
print("Driving...")
def park(self):
print("Parked...")
class Car(Vehicle):
def __init__(self, make, model, year):
super().__init__(make, model, year)
self.make = make
self.model = model
self.year = year
def drive(self):
print("Driving the " + self.make + " " + self.model + " in " + self.year)
```
In this example, the Car class inherits from the Vehicle class and adds its own attributes and methods specific to cars. The Car class also overrides the drive method of the Vehicle class with a new implementation that includes the make, model, and year of the car.
Subclasses can be useful when you want to create a more specialized version of a class that inherits the properties and methods of a parent class. They are commonly used in object-oriented programming to create hierarchical relationships between classes and to promote code reuse and modularity.



