Question: public class BadPoint { private static int x = 0; private static int y = 0; public BadPoint(final int x, final int y) { this.x

public class BadPoint { private static int x = 0; private static int y = 0; public BadPoint(final int x, final int y) { this.x = x; this.y = y; } public double distanceFromOrigin() { return Math.sqrt(x * x + y * y); } } // ... public static void main(final String[] args) { final Point p1 = new BadPoint(6, 8); final Point p2 = new BadPoint(3, 4); System.out.println(p1.distanceFromOrigin()); }

What, if anything, is wrong with the program from the previous question?

  • A. The variables p1 and p2 are final, so the BadPoint instances they refer to cannot be modified.
  • B. The fields (member variables) in the BadPoint class are private instead of public.
  • C. The fields (member variables) in the BadPoint class are static instead of nonstatic instance variables.
  • D. There is nothing wrong with the program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!