Inheritance In Python Is Easy!🐍

Поділитися
Вставка
  • Опубліковано 21 січ 2025

КОМЕНТАРІ • 2

  • @YousefCompSci
    @YousefCompSci  3 місяці тому +1

    # 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()

  • @Monsta1291
    @Monsta1291 3 місяці тому

    beautiful explanation!