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.