Lesson 33 of 34

Inheritance: ഒരു Class-ന് മുകളിൽ നിർമ്മിക്കൽ

10 min 35 XP

ഒരു class-ന് മറ്റൊരു class-ൽ നിന്ന് എല്ലാം inherit ചെയ്ത്, പിന്നെ ചിലത് ചേർക്കുകയോ മാറ്റുകയോ (override) ചെയ്യാം. കോഡ് വീണ്ടും എഴുതേണ്ടതില്ല.

Example: edit me and press Run

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

super() parent class-ന്റെ method call ചെയ്യുന്നു. ഏറ്റവും കൂടുതൽ __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. Interviewers ഇവയെക്കുറിച്ച് പലപ്പോഴും ചോദിക്കും!

Challenge

+35 XP

ഒരു Shape class നൽകിയിട്ടുണ്ട്. __init__(width, height)-ഉം area() method-ഉം (width × height) ഉള്ള Rectangle(Shape) എഴുതൂ. പിന്നെ super() വഴി Rectangle call ചെയ്യുന്ന __init__(side) ഉള്ള Square(Rectangle) എഴുതൂ.

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