aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading makes Difficult using j2se 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading makes Difficult using j2se 5" Watch "Overloading makes Difficult using j2se 5" New topic
Author

Overloading makes Difficult using j2se 5

kirba devi
Ranch Hand

Joined: Jun 29, 2007
Posts: 50
class Dog3 {
static void go(long x) { System.out.print("int "); }
static void go(int x) { System.out.print("double "); }
static void go(double...x) { System.out.print("double "); }
public static void main(String[] args) {
Dog3 d = new Dog3();
double b = 5;
double s = 5;
int l = 5;
float f = 5.0f;
go(b);
go(s);
go(l);
go(f);
}
}

output ouble double double double .How?
my expected output ouble double int double
As per my knowledge,
1)first matching occurs by the use of primitives,it can be widening in some cases.
2)then boxing
3)then var-args

Regards
Kirba

Plase correct me if iam wrong.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18710
    
  40



Maybe this has something to do with... your int version of the method, also prints double.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
kirba devi
Ranch Hand

Joined: Jun 29, 2007
Posts: 50
Hi Wong,
Thanks for identifying the problem.
i have read the rules
2)We can box and widen..//for this can you explain with example.
3)We cannot widen from one wrapper type to another

eg ublic static void go(Long x) {}

Integer x=5;
go(5);
Above example is what rule 3 says? Please correct if iam wrong!!!

4)We cannot widen and box:
eg ublic static void go(Long x) {}

int x=5;
go(5);


Regards
Kirba.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

What is the source of this question ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
kirba devi
Ranch Hand

Joined: Jun 29, 2007
Posts: 50
From K&B book

chpater-3 -Assignment Page NO:244


Regards
Kirba
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading makes Difficult using j2se 5