Lesson 20 of 34

Method Overloading

7 min 30 XP

Parameters ನ ಸಂಖ್ಯೆ ಅಥವಾ type ಬೇರೆಯಾಗಿದ್ದರೆ ಹಲವು methods ಒಂದೇ ಹೆಸರನ್ನು ಹಂಚಿಕೊಳ್ಳಬಹುದು. Java call ನೋಡಿ ಸರಿಯಾದದ್ದನ್ನು ಆರಿಸುತ್ತದೆ. ಇದನ್ನು compile-time polymorphism ಎನ್ನುತ್ತಾರೆ, interview ನ ಕ್ಲಾಸಿಕ್ ಪದ.

Example: edit me and press Run

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

Return type ಮಾತ್ರ ಬದಲಿಸುವುದು overloading ಅಲ್ಲ; ಅದು compile error.

Challenge

+30 XP

area ಎಂಬ ಹೆಸರಿನ ಎರಡು methods ಬರೆಯಿರಿ: ಚೌಕಕ್ಕೆ area(int side) ಮತ್ತು ಆಯತಕ್ಕೆ area(int l, int w). main() ನಲ್ಲಿ s, l ಮತ್ತು w ಓದಿ ಎರಡೂ ವಿಸ್ತೀರ್ಣಗಳನ್ನು print ಮಾಡಿ. Input: 4 3 5 Output: 16 15

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