Lesson 20 of 34

Method Overloading

7 min 30 XP

Parameters-ന്റെ എണ്ണമോ type-ഓ വ്യത്യസ്തമാണെങ്കിൽ പല methods-ന് ഒരേ പേര് ഉപയോഗിക്കാം. Call നോക്കി Java ശരിയായത് തിരഞ്ഞെടുക്കുന്നു. ഇതിനെ 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.