Question

Although this class can be compiled and run as part of a program, objects of this...

Although this class can be compiled and run as part of a program, objects of this class may not work properly. Why?

class Circle {

    private double radius, area;

    public Circle(double radius, double area) {

        setRadius(radius);

        this.area = area;

    }

    public double setRadius(double r) { radius = r; }

    public double getArea() { return area; }

}

(a) The class should be public.

(b) The constructor is not allowed to call the setRadius method.

(c) In the setRadius method, we must use the “this” keyword.

(d) The radius can become “stale.”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER: Here option(B) is correct because setRadius () method is incorrect it should be void method because it has to set the radius and you should use this keyword but not must be.Below snaps have one error after that I correct it.

CODE with Errors:

CODE WITHOUT ERRORS:

Add a comment
Know the answer?
Add Answer to:
Although this class can be compiled and run as part of a program, objects of this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT