| Author |
questions about overloading
|
Storm Zcm
Greenhorn
Joined: Jul 08, 2007
Posts: 10
|
|
In a class, there are a lot of methods with the same name and their parameters's number is also the same. what's the algorithm that java choose method? when there are implicit change,explicit change,boxing. what's the algorithm that java choose method?
|
 |
Pankaj Mittal
Ranch Hand
Joined: Jul 09, 2008
Posts: 32
|
|
Hi buddy try to be precise. When there are several methods are by same name even no of parameters are same but atleast one parameter must be different in order to use method overloading facility. return type, throwing exception type and access specifier may changed. Suppose ----------------------------------------------------- class { void method(int i1,int i2,int i3){} void method(int i1,int i2,float f){} void method(int i1,int i2,double l){} public static void main(String args[]) { method(1,1,1); //will invoke first method method(1,1,1.0f) //will invoke second method method(1,1,1,0) //will invoke third method } } _________________________________________________________________ go through kathy sierra once for more clarification on this topic.
|
2008 SCJP(5.0) 88%
|
 |
Storm Zcm
Greenhorn
Joined: Jul 08, 2007
Posts: 10
|
|
[Edit: non-English text elided. Please post only English.] Refer to which methods to choose in overloading. in my opinion. First of all, the compiler consider exact the same. the method's name must be the same,then the parameters's number must be the same,then the location and parameters type must be the same. If all of these is the same, then choose this methods. If there's implicit conversion. It follow the (byte,char,short)->int->long->float->double to judge the parameters. If there's reference types. First find the reference type,the find whether is the subclass of the reference type. In J2SE 5.0, there's auto-boxing. Then to judge the parameters. [ July 17, 2008: Message edited by: Bear Bibeault ] [ July 17, 2008: Message edited by: Bear Bibeault ]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56191
|
|
"As Angel", please check your private messages for an important administrative matter. And please post only English text. Thanks.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Storm Zcm
Greenhorn
Joined: Jul 08, 2007
Posts: 10
|
|
i'm sorry , i have changed my display name. And I'll use only english in the forum.
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
"Storm Zcm", Please check your private messages regarding an important administrative matter. -Ben
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Sandeep Bhandari
Ranch Hand
Joined: Apr 16, 2004
Posts: 201
|
|
|
And note that its the method calls which make overloaded methods ambiguous as overloaded method calls are resolved at compile time, the compiler flashes error for any ambiguous call.
|
SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
|
 |
 |
|
|
subject: questions about overloading
|
|
|