Java Overloaded Constructor Calls
Identify, using its signature, the correct constructor being called.
Consider the following class with overloaded constructors:
public class Temperature {
private double celsius;
public Temperature(double c) {
celsius = c;
}
public Temperature(int f) {
celsius = (f - 32) * 5.0 / 9.0;
}
public Temperature(double f, boolean isFahrenheit) {
if (isFahrenheit) {
celsius = (f - 32) * 5.0 / 9.0;
} else {
celsius = f;
}
}
}
A programmer creates objects with these statements:
Temperature t1 = new Temperature(25.0);
Temperature t2 = new Temperature(77);
Temperature t3 = new Temperature(98.6, true);
Temperature t4 = new Temperature(20, false);
Which statement about these constructor calls is most accurate?
A
t2 and t4 will both cause compilation errors due to type mismatches
B
t1, t2, and t3 will compile successfully, but t4 will cause a compilation error
C
All four constructor calls will compile and execute successfully
D
Only t1 and t3 will compile successfully
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | zmirzaucl | 1 | 1 | 0m 00s | 100 |
| #2 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #3 | patrickmeijer009 | 1 | 3 | 1m 10s | 10 |
| #4 | psak12 | 1 | 1 | 1m 42s | -2 |
| #5 | sailajavadlamani33 | 0 | 2 | 0m 00s | -20 |
| #6 | jeonsaw1723 | 1 | 1 | 2m 01s | -21 |
| #7 | richa.tuli | 1 | 2 | 2m 17s | -47 |
| #8 | y.seong2027 | 1 | 1 | 2m 34s | -54 |
| #9 | 29AmeliaC | 1 | 2 | 6m 14s | -284 |
| #10 | lsj08030922 | 1 | 2 | 7m 05s | -335 |
APFIVE