What is method overloading? Explain with an example. Ans. It is a form of static polymorphism that allows multiple methods to have the same name but with different parameters or argument types. When an overloaded method is called, the compiler determines which method to call based on the number, type, and order of the arguments passed to the method. The method name and the number, type, and order of the parameters must be different in each overloaded method. Example of method overloading in OOPs For example, consider a class called “Math” that contains two overloaded methods called “add”. The first method takes two integers as arguments and returns their sum, while the second method takes two doubles as arguments and returns their sum. When we call the “add” method with two integers, the first method is called, and when we call the “add” method with two doubles, the second method is called. - Study24x7
Social learning Network
3 followers study24x7 15 Jul 2024 11:43 AM study24x7 study24x7

What is method overloading? Explain with an example.
Ans. It is a form of static polymorphism that allows multiple methods to have the same name but with different parameters or argument types. When an overloaded method is called, the compiler determines which method to cal...

See more

study24x7
Write a comment
Related Questions
500+   more Questions to answer
Most Related Articles