# Inheritance allows us to define a class that inherits all the methods and properties from another class class Vehicle: works = True def move(self): print("This vehicle is moving") def stop(self): print("This vehicle is stopping") class Car(Vehicle): def drive(self): print("This car is driving") class Submarine(Vehicle): def sink(self): print("This submarine is sinking") class Plane(Vehicle): def fly(self): print("This plane is flying") car = Car() submarine = Submarine() plane = Plane() print(submarine.works) car.move() plane.stop() car.drive() plane.fly() submarine.sink()
# Inheritance allows us to define a class that inherits all the methods and properties from another class
class Vehicle:
works = True
def move(self):
print("This vehicle is moving")
def stop(self):
print("This vehicle is stopping")
class Car(Vehicle):
def drive(self):
print("This car is driving")
class Submarine(Vehicle):
def sink(self):
print("This submarine is sinking")
class Plane(Vehicle):
def fly(self):
print("This plane is flying")
car = Car()
submarine = Submarine()
plane = Plane()
print(submarine.works)
car.move()
plane.stop()
car.drive()
plane.fly()
submarine.sink()
beautiful explanation!