About Question enthuware.ocajp.i.v8.2.1461 :

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

Moderator: admin

Post Reply
scyber
Posts: 3
Joined: Sat Jul 08, 2017 4:42 am
Contact:

About Question enthuware.ocajp.i.v8.2.1461 :

Post by scyber »

public class TestOverLoad {

public static void printSum(double a, double b){
System.out.println("In double "+(a+b));
}
public static void printSum(float a, float b){
System.out.println("In float "+(a+b));
}

public static void main(String[] args) {
printSum(1.0, 2.0);
}

}

In the console I get
In double 3.0

The answer point that In double 3
why?

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

Re: About Question enthuware.ocajp.i.v8.2.1461 :

Post by admin »

I see that option 3 i.e. In double 3.0 is set as the correct answer.
If you like our products and services, please help us by posting your review here.

jackdaniels
Posts: 10
Joined: Sun Feb 04, 2018 7:05 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1461 :

Post by jackdaniels »

I tried the experiment in the recommendation for this question.
Note that if you call printSum(1, 2) , printSum(float, float) would have been invoked instead of printSum(double, double) because a float is closer than a double to an int.
This did not compile (Cannot resolve method printSum(int, int)).

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

Re: About Question enthuware.ocajp.i.v8.2.1461 :

Post by admin »

Please post the complete code that you tried.
If you like our products and services, please help us by posting your review here.

jackdaniels
Posts: 10
Joined: Sun Feb 04, 2018 7:05 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1461 :

Post by jackdaniels »

Code: Select all

public class ParamTest {
    public static void printSum(double a, double b) {
        System.out.println("In double " + (a + b));
    }

    public static void printSum(float a, float b) {
        System.out.println("In float " + (a + b));
    }

    public static void main(String[] args) {
        printSum(1.0, 2.0);
        printsum(1, 2);//Error
    }
}

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

Re: About Question enthuware.ocajp.i.v8.2.1461 :

Post by admin »

You have a typo in your code. You are trying to call printsum instead of printSum.
If you like our products and services, please help us by posting your review here.

jackdaniels
Posts: 10
Joined: Sun Feb 04, 2018 7:05 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1461 :

Post by jackdaniels »

Thanks!

(facepalm :cry: )

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

Re: About Question enthuware.ocajp.i.v8.2.1461 :

Post by admin »

jackdaniels wrote:
Wed Feb 20, 2019 6:24 am
Thanks!

(facepalm :cry: )
can't avoid that if you are jackdaniels ... :cheers:
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests