| 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
Initializing an Object in a Constructor
< Prev
Next >

Consider the following Point and Circle class declarations.

public class Point
{
    private double x; // x-coordinate
    private double y; // y-coordinate

    public Point()
    {
        x = 0;
        y = 0;
    }

    public Point(double a, double b)
    {
        x = a;
        y = b;
    }
    // There may be instance variables, constructors, and methods that are not shown.
}

public class Circle
{
    private Point center;
    private double radius;

    /** Constructs a circle where (a, b) is the center and r is the radius. */
    public Circle(double a, double b, double r)
    {
        /* missing code */
    }
}

Which of the following code segments, if substituted for /* missing code */, will correctly implement the Circle constructor?

I. center = new Point();
   radius = r;

II. center = new Point(a, b);
    radius = r;

III. center = new Point();
     center.x = a;
     center.y = b;
     radius = r;
A

II only

B

I and II only

C

III only

D

I only

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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