answersLogoWhite

0


Best Answer

Suppose that you have a class that can draw various types of data (strings, integers, and so on) and that contains a method for drawing each data type. In other languages, you have to think of a new name for each method, for example, drawString, drawInteger, drawFloat, and so on. In the Java programming language, you can use the same name for all the drawing methods but pass a different type of argument to each method. Thus, the data drawing class might declare three methods named draw, each of which takes a different type of argument.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

Overloading a method allows you to keep your interface consistent, and allows you to logically call the same method regardless of the types of data you are passing in. You will find that using the same name will help you remember what a procedure does, as opposed to having to come up with new names or a naming convention, to help you keep things straight.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

Overloading is mainly used to pass the different parameters dynamically, during the runtime for the same time. So, depending on the parameters we passed, it calls the appropriate method.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the Advantage of method overloading?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is constructor overloading same as method overloading.yes or no. explain?

yes,because in constructor overloading constructor have same and different parameter list. In method overloading method have same name and different parameter list.


Define method overloading and write two method headers that together exhibit overloading?

Method overloading is when two or more methods have the same name, but the computer can differentiate between the methods by looking at the parameters. Example: public static void go(int x) public static void go(double x) If you pass an int, the first method would be called. If you pass a double, the second method would be called


What is method overloading and constructor overloading explain with?

method overriding :method overriding means redefine methods in sub classes they already defined in the Super classes.method overloading : It means methods with the same name but with a different signature exist in one class


Is overloading done at compile time or run time?

Overloading will be done at compile time itself. Proof: If you try to narrow down the access modifier for a method from public in the parent class to private in the child class while overloading, the compiler will not let you do it.


What is the scope of method overloading and overriding?

Overloading happens when you have multiple methods in the current class that have the same name but different signature. The scope of method overloading is "Within the current class" Overriding happens when your current class extends another class (the parent class) and provides implementation for a method that is already available in the parent class. The scope of method overriding too is "Within the current class"

Related questions

What is advantage of overloading main method?

Practically speaking, there is no advantage in overloading the main method because, eitherways the main method of the current class only gets executed and not any of the parent classes, the current class might extend.


Is constructor overloading same as method overloading.yes or no. explain?

yes,because in constructor overloading constructor have same and different parameter list. In method overloading method have same name and different parameter list.


How the compiler compiles overloaded method?

method overloading occurs when we use two functions or more with the same name.In function overloading compiler detect which method is call actually throw the parameters passed to the methods.In function overloading parameters of functions are different.


Differene betwee constructor overloading same as method overloading?

A constructor is just a special form of a method. You can overload constructors in the exact same way as you can overload any other method.


What is method overriding and overloading in java?

Overloading is the means by which we can provide two or more different definitions of the same method in the same namespace. Overriding is the means by which a derived class may redefine the meaning of a base class method.


Is it possible to do method overloading and overriding at a time?

no we cannot do both at the same time because overloading requires different arguments and overriding dosenot


Define method overloading and write two method headers that together exhibit overloading?

Method overloading is when two or more methods have the same name, but the computer can differentiate between the methods by looking at the parameters. Example: public static void go(int x) public static void go(double x) If you pass an int, the first method would be called. If you pass a double, the second method would be called


What is the difference between polymorphism and method overloading in java?

The dictionary definition of polymorphism refers to a principle in biology in which an organism or species can have many different forms or stages. This principle can also be applied to object-oriented programming and languages like the Java language. Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.Overriding and Overloading are two techiques to achive polymorphism in Java.Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.


What is method overloading and constructor overloading explain with?

method overriding :method overriding means redefine methods in sub classes they already defined in the Super classes.method overloading : It means methods with the same name but with a different signature exist in one class


How you compare and contrast overloading and overriding methods in java?

Method overloading is when you have multiple methods in a class that have the same name but a different signature. Method overriding is similar to method overloading, with a small difference. In overriding, a method in a parent class is overridden in the child class. The method in the child class will have the same signature as that of the parent class. Since the method in the child class has the same signature & name as the method of its parent class, it is termed as overriding. In situations where you may have to explicitly call the parent class method you can use the "super" keyword and for explicitly calling the current objects method you can use the "this" keyword.


Is overloading done at compile time or run time?

Overloading will be done at compile time itself. Proof: If you try to narrow down the access modifier for a method from public in the parent class to private in the child class while overloading, the compiler will not let you do it.


What does overloading rely on to identify the correct method?

If more than one method shares the same name, the number of arguments provided is used to identify the correct method.