Method signatures (II)

4 March 2008

Do read Method signatures (I) before this one since it is a continuation to it.

Answering the raised question: Some of you might think it is ok to have methods with same names, same no of parameters and all the variables have same datatype but with different since JRE will know which method to call depending on the variable that will get the value returned by the method.

Some of you might this that it is a run time error.

The answer is: it’s a compile time error. Let me give you an example:

public  int getValue(int a)
{
System.out.println("I m in int getValue(int)");
return 1;
}
 
public  float getValue(int a)
{
System.out.println("I m in float getValue(int)");
return 1.5f;
}

Error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem

Actually, Java compiler treats both method same and duplicate method declaration is not allowed.

I hope I was able to provide interesting example.

Happy coding.

del.icio.us:Method signatures (II)  digg:Method signatures (II)  spurl:Method signatures (II)  wists:Method signatures (II)  simpy:Method signatures (II)  newsvine:Method signatures (II)  blinklist:Method signatures (II)  furl:Method signatures (II)  reddit:Method signatures (II)  fark:Method signatures (II)  blogmarks:Method signatures (II)  Y!:Method signatures (II)  smarking:Method signatures (II)  magnolia:Method signatures (II)  segnalo:Method signatures (II)  gifttagging:Method signatures (II)

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Method signatures (II)

Leave a Reply