About Question enthuware.ocajp.i.v7.2.1058 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1058 :

Post by ETS User »

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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1058 :

Post by admin »

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

meghajor
Posts: 7
Joined: Fri Nov 20, 2015 7:03 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1058 :

Post by meghajor »

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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1058 :

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests