Top Posters
Since Sunday
1
1
New Topic  
toripollard8 toripollard8
wrote...
Posts: 486
4 years ago
Analyze the following code.

public class Test {
public static void main(String[] args) {
System.out.println(max(1, 2));
}

public static double max(int num1, double num2) {
System.out.println("max(int, double) is invoked");
if (num1 > num2)
return num1;
else
return num2;
}
 
public static double max(double num1, int num2) {
System.out.println("max(double, int) is invoked");
if (num1 > num2)
return num1;
else
return num2;
}
}


▸ The program runs and prints "max(int, double) is invoked" followed by 2.

▸ The program runs and prints 2 followed by "max(double, int)" is invoked.

▸ The program cannot compile because the compiler cannot determine which max method should be invoked.

▸ The program cannot compile because you cannot have the print statement in a non-void method.

▸ The program runs and prints 2 followed by "max(int, double)" is invoked.
Textbook 
Introduction to Java Programming, Comprehensive Version

Introduction to Java Programming, Comprehensive Version


Edition: 10th
Author:
Read 49 times
1 Reply
Replies
Answer verified by a subject expert
mnp2357mnp2357
wrote...
Posts: 404
4 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here
1

Related Topics

toripollard8 Author
wrote...

4 years ago
This helped my grade so much Perfect
wrote...

Yesterday
this is exactly what I needed
wrote...

2 hours ago
Good timing, thanks!
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  925 People Browsing
Related Images
  
 1052
  
 2781
  
 313
Your Opinion
What percentage of nature vs. nurture dictates human intelligence?
Votes: 432