About Question enthuware.ocajp.i.v8.2.1461 :
Moderator: admin
-
- Posts: 3
- Joined: Sat Jul 08, 2017 4:42 am
- Contact:
About Question enthuware.ocajp.i.v8.2.1461 :
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?
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?
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1461 :
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.
-
- Posts: 10
- Joined: Sun Feb 04, 2018 7:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1461 :
I tried the experiment in the recommendation for this question.
This did not compile (Cannot resolve method printSum(int, int)).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.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1461 :
Please post the complete code that you tried.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sun Feb 04, 2018 7:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1461 :
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
}
}
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1461 :
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.
-
- Posts: 10
- Joined: Sun Feb 04, 2018 7:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1461 :
Thanks!
(facepalm )
(facepalm )
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1461 :
can't avoid that if you are jackdaniels ...
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 68 guests