The explanation for this says that if the third test1 method - test1(int i, int j) were removed the the program would not compile because the remaining two methods are equally applicable and equally specific.
On my machine with Java7 installed I get no compile time or runtime errors when I remove the third method with the two int parameters. My machine returns 1 as the output. So it returns the one with the int and the var-args over the method with just var-args.
About Question enthuware.ocajp.i.v7.2.1058 :
Moderator: admin
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1058 :
Are you sure you ran the same code as given in the question? Because I tried it and I get:
Varargs.java:3: error: reference to test1 is ambiguous, both method test1(int,in
t...) in Varargs and method test1(int...) in Varargs match
test1(10, 20); //1
^
1 error
-
- Posts: 7
- Joined: Fri Nov 20, 2015 7:03 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1058 :
I ran the same code on my computer.I commented two methods. The uncommented method is printing its output.
But when I only comment the last method, it says ambiguous.
Pls explain
But when I only comment the last method, it says ambiguous.
Pls explain
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1058 :
Please post the exact code that you ran and the expected and actual output so that it is clear what you are asking.
thank you,
Paul.
thank you,
Paul.
Who is online
Users browsing this forum: No registered users and 6 guests