Inheritance In Python Is Easy!🐍

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 2024

ความคิดเห็น • 2

  • @YousefCompSci
    @YousefCompSci  หลายเดือนก่อน +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 หลายเดือนก่อน

    beautiful explanation!