| preferred AP College board partner for AP classes
AP Computer Science A/Unit 2: Using Objects
Start Practice Test
Share
medium Solved by 11 students
Java Overloaded Constructor Calls
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1zmirzaucl11 0m 00s 100
#2kaisuki12 0m 00s 90
#3patrickmeijer00913 1m 10s 10
#4psak1211 1m 42s -2
#5sailajavadlamani3302 0m 00s -20
#6jeonsaw172311 2m 01s -21
#7richa.tuli12 2m 17s -47
#8y.seong202711 2m 34s -54
#929AmeliaC12 6m 14s -284
#10lsj0803092212 7m 05s -335
APFIVE © 2020.
Email: [email protected]|Privacy Policy