Lesson 33 of 34

Inheritance: ఒక Class పై నిర్మించడం

10 min 35 XP

ఒక class మరో class నుండి అన్నిటినీ వారసత్వంగా పొంది, కొత్తవి కలపవచ్చు లేదా మార్చవచ్చు (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 ను పిలుస్తుంది. ఇది ఎక్కువగా __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. ఇంటర్వ్యూలలో వీటి గురించి తరచుగా అడుగుతారు!

Challenge

+35 XP

Shape class ఇవ్వబడింది. __init__(width, height), area() method (width × height) ఉన్న Rectangle(Shape) రాయండి. తర్వాత super() ద్వారా Rectangle ను పిలిచే __init__(side) ఉన్న Square(Rectangle) రాయండి.

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