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) लिहा. मग Square(Rectangle) लिहा ज्याचे __init__(side) super() द्वारे Rectangle call करते.

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