Có, Python hỗ trợ nhiều kế thừa. Giống như C ++, một lớp có thể được lấy từ nhiều lớp cơ sở trong Python. Điều này được gọi là nhiều kế thừa.
Trong nhiều kế thừa, các tính năng của tất cả các lớp cơ sở được kế thừa vào lớp dẫn xuất. Hãy cho chúng tôi xem cú pháp -
Cú pháp
Class Base1: Body of the class Class Base2: Body of the class Class Base3: Body of the class . . . Class BaseN: Body of the class Class Derived[Base1, Base2, Base3, … , BaseN]: Body of the class
Lớp dẫn xuất kế thừa từ cả Base1, Base2 và Base3Classes.
Thí dụ
Trong ví dụ dưới đây, lớp chim thừa hưởng lớp động vật.
Animal là lớp cha mẹ còn được gọi là siêu lớp hoặc lớp cơ sở.
Bird là lớp trẻ em còn được gọi là lớp phụ hoặc lớp có nguồn gốc.
Phương pháp class đảm bảo rằng Bird là một lớp con của lớp động vật.
class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Đầu ra
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True
Cập nhật vào ngày 12 tháng 8 năm 2022 12:19:02
- Câu hỏi và câu trả lời liên quan
- Liệu kế thừa của MySQL hỗ trợ?
- Java có hỗ trợ kế thừa lai không?
- Java có hỗ trợ nhiều kế thừa không? Tại sao? Làm thế nào chúng ta có thể giải quyết điều này?
- Python có hỗ trợ đa hình không?
- Super [] của Python hoạt động như thế nào với nhiều kế thừa?
- Làm thế nào để thừa kế lớp hoạt động trong Python?
- C# và nhiều kế thừa
- Java và nhiều kế thừa
- Nhiều kế thừa trong C ++
- Nhiều kế thừa trong JavaScript
- JavaScript có hỗ trợ phạm vi khối không?
- Selenium có hỗ trợ trình duyệt Safari không?
- Làm thế nào chúng ta có thể mở rộng nhiều lớp Python trong kế thừa?
- Nhiều kế thừa bằng giao diện trong Java
- Sự khác biệt giữa đơn và nhiều kế thừa
Nhiều kế thừa thừa kế này cho phép một lớp con được thừa hưởng từ nhiều lớp cha mẹ. Loại kế thừa này không được hỗ trợ bởi các lớp Java, nhưng Python không hỗ trợ loại kế thừa này.inheritance in Python.
Python có hỗ trợ tất cả sự kế thừa không?
Kế thừa là một tính năng cần thiết của mọi ngôn ngữ lập trình hướng đối tượng. Điều này có nghĩa là Python hỗ trợ thừa kế và như bạn sẽ thấy sau này, đó là một trong số ít ngôn ngữ hỗ trợ nhiều kế thừa.
Loại kế thừa nào không được hỗ trợ?
Để ngăn chặn tình huống như vậy, nhiều kế thừa không được phép trong Java.
Example:
Python3
class
Parent:
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
2class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
8class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
8class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
____10
1class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True4
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in parent class. This function is in child class.0
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in parent class. This function is in child class.2
This function is in parent class. This function is in child class.3
This function is in parent class. This function is in child class.4
This function is in parent class. This function is in child class.2
This function is in parent class. This function is in child class.6
This function is in parent class. This function is in child class.2
This function is in parent class. This function is in child class.8
Output:
This function is in parent class. This function is in child class.
Nhiều kế thừa: & nbsp;
Khi một lớp có thể được lấy từ nhiều lớp cơ sở, loại thừa kế này được gọi là nhiều kế thừa. Trong nhiều kế thừa, tất cả các tính năng của các lớp cơ sở được kế thừa vào lớp dẫn xuất. & NBSP;
Example:
Python3
class
Father : RAM Mother : SITA0
0class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Father : RAM Mother : SITA2
This function is in parent class. This function is in child class.3
Father : RAM Mother : SITA4
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Father : RAM Mother : SITA7
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Lal mani Grandfather name : Lal mani Father name : Rampal Son name : Prince4
class
Lal mani Grandfather name : Lal mani Father name : Rampal Son name : Prince6
0class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Lal mani Grandfather name : Lal mani Father name : Rampal Son name : Prince8
This function is in parent class. This function is in child class.3
Father : RAM Mother : SITA4
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in parent class. This function is in child 1. This function is in parent class. This function is in child 2.3
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in school. This function is in student 1.0
class
This function is in school. This function is in student 1.2
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in school. This function is in student 1.5
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
1class
23class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in school. This function is in student 1.0
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
8class
23class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Lal mani Grandfather name : Lal mani Father name : Rampal Son name : Prince4
Parent:
2
This function is in parent class. This function is in child class.3
Parent:
4Parent:
5
This function is in parent class. This function is in child class.3
Parent:
7Parent:
8
This function is in parent class. This function is in child class.3
00class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
01class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Output:
Father : RAM Mother : SITA
Thừa kế đa cấp & nbsp ;: :
Trong kế thừa đa cấp, các tính năng của lớp cơ sở và lớp dẫn xuất được tiếp tục di truyền vào lớp dẫn xuất mới. Điều này tương tự như một mối quan hệ đại diện cho một đứa trẻ và một ông nội. & Nbsp;
Example:
Python3
class
03class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
06class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
08class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in parent class. This function is in child class.3
13class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
15class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
06class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
20class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
23class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in parent class. This function is in child class.3
25class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
27class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
29class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
31class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
06class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
36class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
39class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in parent class. This function is in child class.3
41class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
43class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
45class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
48class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
54class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
23class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
57class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
61class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
23class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
This function is in school. This function is in student 1.0
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
68class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
23class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
71class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Parent:
2
This function is in parent class. This function is in child class.3
74class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
75class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
226class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
82class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
83class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Output:
Lal mani Grandfather name : Lal mani Father name : Rampal Son name : Prince
Di truyền phân cấp: & nbsp;
Khi nhiều hơn một lớp dẫn xuất được tạo ra từ một cơ sở duy nhất, loại thừa kế này được gọi là kế thừa phân cấp. Trong chương trình này, chúng tôi có một lớp cha mẹ [cơ sở] và hai lớp [có nguồn gốc].
Example:
Python3
class
Parent:
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
2class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
8class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
97class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
____10
1class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True4
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True06
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True09
Is
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True18
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True20
This function is in parent class. This function is in child class.3
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True22
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True23
This function is in parent class. This function is in child class.3
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True25
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True26
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True27
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True28
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True29
Output:
This function is in parent class. This function is in child 1. This function is in parent class. This function is in child 2.
Di truyền lai: & nbsp;
Di truyền bao gồm nhiều loại thừa kế được gọi là kế thừa lai.
Example:
Python3
class
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True31
0____11class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
2class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True40
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
8class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
____10
1class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True4
3class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
4class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True52
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
class
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True09
Is
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True64
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True20
This function is in parent class. This function is in child class.3
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True22
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True23
This function is in parent class. This function is in child class.3
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True25
5class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
6class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
7class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True76
9class Animal: def eat[self]: print["It eats insects."] def sleep[self]: print["It sleeps in the night."] class Bird[Animal]: def fly[self]: print["It flies in the sky."] def sing[self]: print["It sings a song."] print[issubclass[Bird, Animal]] Koyal= Bird[] print[isinstance[Koyal, Bird]] Koyal.eat[] Koyal.sleep[] Koyal.fly[] Koyal.sing[]
Di truyền lai: & nbsp;
This function is in parent class. This function is in child class.2
This function is in parent class. This function is in child class.6
This function is in parent class. This function is in child class.2
This function is in parent class. This function is in child class.8
Output:
This function is in school. This function is in student 1.