What is the result?

Given:
<code>
class Overloading {
int x(double d) {
System.out.println(“one”);
return 0;
}
String x(double d) {
System.out.println(“two”);
return null;
}
double x(double d) {
System.out.println(“three”);
return 0.0;
}
public static void main(String[] args) {
new Overloading().x(4.0);
}
</code>
What is the result?

Given:

class Overloading {
int x(double d) {
System.out.println("one");
return 0;
}
String x(double d) {
System.out.println("two");
return null;
}
double x(double d) {
System.out.println("three");
return 0.0;
}
public static void main(String[] args) {
new Overloading().x(4.0);
}

What is the result?

A.
one

B.
two

C.
three

D.
Compilation fails.



Leave a Reply 4

Your email address will not be published. Required fields are marked *


sully

sully

isn’t this one a repeated question already done
think i saw that on 1 or 2 other questions

noname

noname

I try to compile it.
D is correct.

noname

noname

The compile says the method is already defined.

True Overloading:
////////////////////
int x(double d) {
System.out.println(“one”);
return 0;
}
int x(int d) {
System.out.println(“two”);
return 0;
}
int x(String d) {
System.out.println(“three”);
return 0;
}
//////////////////////

noname

noname

or

////////////////////
int x(int d) {
System.out.println(“one”);
return 0;
}
String x(float d) {
System.out.println(“two”);
return null;
}
double x(double d) {
System.out.println(“three”);
return 0.0;
}
//////////////////////