Question

Refer to the following class. Public Class Point. {, private int myX; private int myY; public Point (), {, myX=0; myY=0; }. public Point(int x, int y), {, myX=x; myY=y; }, public int getX(), {, return myX; }, public int getY(), {, return myY; }, }. Which of the following statements is true regarding the Point class? (A) The calls won't compile because there are two methods named Point. (B) Variables myX and myY can be changed from outside the class. (c) Point objects are immutable. (D) It's impossible to create Point objects with coordinates other than (0, 0). (E) Giving myX and myY private visibility was a poor design decision.

Solution

Verified

Step 1

1 of 2

Option A is not correct because a class can have two or more constructors. There is nothing wrong with that.

Option B is not correct because class Point don't have setter methods and access modifier of both variables, myX and myY, is private. So, they can't be accessed from outside the Point class.

Option C is correct because once a Point is created, there is no way its private members can be accessed and hence, they can't be changed.

Option D is not correct because there is a parametrized constructor inside Point class and hence Point other than (0,0) can be created.

Option E is not correct because it is a good design practice to set access modifiers of a class member variables to private so that no one outside the class can change it.

Hence, only Option C\color{#4257b2}\text{Option C} is correct.

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Recommended textbook solutions

Java Software Solutions for AP Computer Science 3rd Edition by Cara Cocking, John Lewis, William Loftus

Java Software Solutions for AP Computer Science

3rd EditionCara Cocking, John Lewis, William Loftus
499 solutions
Java Methods: Object-Oriented Programming and Data Structures 3rd Edition by Gary Litvin, Maria Litvin

Java Methods: Object-Oriented Programming and Data Structures

3rd EditionGary Litvin, Maria Litvin
285 solutions

Related questions