Lesson 33 of 34

Inheritance: பரம்பரை

10 min 35 XP

ஒரு class மற்றொரு class-ன் அனைத்தையும் பெற்றுக்கொள்ளலாம் (inherit). பின்னர் புதியவற்றைச் சேர்க்கலாம் அல்லது மாற்றலாம் (override). இதனால் code மீண்டும் எழுத வேண்டியதில்லை.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

super() மூலம் பெற்றோர் class-ன் method-ஐ அழைக்கலாம். பொதுவாக __init__-ல் பயன்படுத்துவோம்.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

OOP-ன் நான்கு தூண்கள்: Encapsulation, Inheritance, Polymorphism, Abstraction. Interview-களில் இவை பற்றி அடிக்கடி கேட்பார்கள்!

Challenge

+35 XP

Shape class கொடுக்கப்பட்டுள்ளது. Rectangle(Shape) class எழுதுங்கள்: __init__(width, height) மற்றும் area() method (width × height). பிறகு Square(Rectangle) எழுதுங்கள்: __init__(side) மட்டும்; super() பயன்படுத்தி Rectangle-ஐ அழையுங்கள்.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.