Overriding Method
Overriding Method คือการแทนที่ของ method class แม่
โดยการสร้าง method ที่ class ลูก
ซึ่งให้มีชื่อ method เหมือนกับ method class แม่
รูปโค้ดใน โปรแกรม
- 02.png (19.01 KiB) Viewed 2032 times
ผลลัพธ์ที่ได้
- จะแสดงค่า method ลูก แทนของ แม่
- 020.png (8.81 KiB) Viewed 2032 times
โค้ดที่ใช้ในการ run
โค้ด: เลือกทั้งหมด
class A:
def method (self):
print('calling A method')
class B(A):
def method (self):
print('calling B method')
c = B()
print('_______________')
c.method()
print('_______________')
คลิปประกอบการสอน