English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

Overloading methods
.
1.same method names
2.different signatures (i)the return type may or may not be same
(ii)but the arguments you r passing "must" be distinct

if your program satisfies these two conditions, then you can use method overloading in any circumstances... not particularly in classes! globally, locally to a function etc.

2007-02-13 05:56:42 · answer #1 · answered by KillingJoke 3 · 1 0

Do you understand what method overloading is? An overloaded method must reside in the same class as the method it is overloading. E.g. I will write a small program, with 1 method called myMethod(). I will then overload myMethod(), so that it takes in a String, then a String and an int.

class MyClass
{
String myWords;
int myNumber;

public void myMethod()
{
this.myWords = "blank";
this.myNumber=0;
}

public void myMethod(String myWords)
{
this.myWords=myWords;
this.myNumber=0;
}

public void myMethod(String myWords, int myNumber)
{
this.myWords=myWords;
this.myNumber=myNumber;
}

}

Capiche? I can be more specific if you give me more information. Be as exact as you can.

2007-02-13 11:03:39 · answer #2 · answered by eoin2000 1 · 1 0

i think the short answer is 'yes'.

two methods in different classes won't collide, e.g. they can have the exact same signature.

in the same class, to make a function with the same name as another one, you've got to change the args and/or return type. (e.g. override it)

but, if you have two classes with one function each, each can be overidden individually, but have no effect on each other.

2007-02-13 17:02:55 · answer #3 · answered by fixedinseattle 4 · 0 0

fedest.com, questions and answers