| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
easy Solved by 1 students
Java Superclass Constructor Initialization
< Prev
Next >

Which of the following code segments can replace /* missing code */ so that the Square class constructor initializes the Rectangle class instance variables height and width to x?

Consider the following class definitions.

public class Rectangle
{
    private int height;
    private int width;

    public Rectangle()
    {
        height = 1;
        width = 1;
    }

    public Rectangle(int x)
    {
        height = x;
        width = x;
    }

    public Rectangle(int h, int w)
    {
        height = h;
        width = w;
    }
    // There may be methods that are not shown.
}

public class Square extends Rectangle
{
    public Square(int x)
    {
        /* missing code */
    }
}

Which of the following code segments can replace /* missing code */ so that the Square class constructor initializes the Rectangle class instance variables height and width to x?

A

super();

B

Rectangle(x);

C

height = x; width = x;

D

super(x);

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

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy