Java Overloaded Constructor Calls
Consider the following Temperature class, which contains 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;
}
}
}
The following code segment attempts to create several Temperature objects.
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 best describes the result of compiling this code segment?
A
Only t1 and t3 will compile successfully
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
t2 and t4 will both cause compilation errors due to type mismatches
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | zmirzaucl | 1 | 1 | 0m 00s | 100 |
| #2 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #3 | liuwilliam072410 | 1 | 2 | 1m 07s | 23 |
| #4 | patrickmeijer009 | 1 | 3 | 1m 10s | 10 |
| #5 | psak12 | 1 | 1 | 1m 42s | -2 |
| #6 | sailajavadlamani33 | 0 | 2 | 0m 00s | -20 |
| #7 | jeonsaw1723 | 1 | 1 | 2m 01s | -21 |
| #8 | richa.tuli | 1 | 2 | 2m 17s | -47 |
| #9 | y.seong2027 | 1 | 1 | 2m 34s | -54 |
| #10 | ananyetyagi | 0 | 1 | 1m 55s | -125 |
Items per page:
10
1 – 10 of 13
APFIVE