aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Barry Boone #29 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Barry Boone #29" Watch "Barry Boone #29" New topic
Author

Barry Boone #29

Indy
Ranch Hand

Joined: Apr 24, 2000
Posts: 44
Question 29: What is the result of executing the following code: class Test {
public static void main(String[] args) {
Test t = new Test();
t.test(1.0, 2L, 3);
}
void test(double a, double b, short c) {
System.out.println("1");
}
void test(float a, byte b, byte c) {
System.out.println("2");
}
void test(double a, double b, double c) {
System.out.println("3");
}
void test(int a, long b, int c) {
System.out.println("4");
}
void test(long a, long b, long c) {
System.out.println("5");
}
}
A.1
B.2
C.3
D.4
E.5
The answer is C.
Can someone explain to me why the answer is C, not A? "3" can not be passed as short?
The first test method "double double short" would match the args, doesn't it?
Thanks a lot.

[This message has been edited by Indy (edited April 30, 2000).]
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Indy,
Plese align your code and give no. for your answers also.
You are very welcome to post any small doubts. But try to put one qstn per post please unless you can't separate the 2 qstns.
regds
maha anna
Indy
Ranch Hand

Joined: Apr 24, 2000
Posts: 44
all right, maha. I will post them separately.
Indy
priyavardheesh
Greenhorn

Joined: May 01, 2000
Posts: 16
hi,
the arithmetic promotion takes place here and the last argument is considered as an int value and so can't be assigned to a short and hence all the arguments are promoted to double
priya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Barry Boone #29
 
Similar Threads
Primitive Data Types
conversion and casting
Overloaded methods - Boone's Mock Question
Why this Output?
boone exam q -- assignments, help