| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
Share
About Exam
medium Solved by 2 students
Java Constructor Chaining
< Prev
Next >

Consider the following Rectangle class definition:

public class Rectangle {
    private double width;
    private double height;
    private String color;
    
    public Rectangle() {
        /* constructor body A */
    }
    
    public Rectangle(double w, double h) {
        /* constructor body B */
    }
    
    public Rectangle(double w, double h, String c) {
        /* constructor body C */
    }
}

Which set of implementations for constructor bodies A, B, and C correctly uses constructor chaining to centralize all initialization logic in the three-parameter constructor?

A

A: this(1.0, 1.0, “white”); B: this(w, h, “white”); C: width = w; height = h; color = c;

B

A: width = 1.0; height = 1.0; color = “white”; B: width = w; height = h; color = “white”; C: width = w; height = h; color = c;

C

A: this(1.0, 1.0); B: width = w; height = h; color = “white”; C: width = w; height = h; color = c;

D

A: Rectangle(1.0, 1.0, “white”); B: Rectangle(w, h, “white”); C: width = w; height = h; color = c;

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki14 0m 00s 70
#2bommasam00003 3m 29s -239
#3gtsak3101 4m 05s -255
#4y.seong202712 13m 44s -734
Items per page:
10
1 – 4 of 4

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy