A class can have many methods with the same name as long as the number of parameters or type of parameters is different. This OOP concept is known as

Options
- Method Invocating
- Method Overriding
- Method Labeling
- Method Overloading


CORRECT ANSWER : Method Overloading

Discussion Board
Method Overloading

Method overloading can have the same name if they have different parameter lists. So, method overloading happens only when:

1. The number of parameters is different for the methods.
2. The parameter types are different (like changing a parameter from float to an int).

It is difficult to have many methods for the same function for example draw is the method and the purpose is to draw triangle, rectangle, etc. So, in general scenario you need to define different methods having different parameters so Java gives a method of overloading which allows you to carry one method with different parameters.

public class DataArtist {
...
public void draw(String s) {
...
}
public void draw(int i) {
...
}
public void draw(double f) {
...
}
public void draw(int i, double f) {
...
}
}

Rohit Sharma 07-28-2014 03:46 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement