This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Barry Boone #29

 
Indy
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all right, maha. I will post them separately.
Indy
 
priyavardheesh
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic