13
© Pearson Education Limited, 2015
Answer: C
Explanation: C) In answers A-D, all of the code works properly by comparing the mouse’s
current location to the box. If the mouse is inside of the box when the event occurs, then inside
is set to true. However, the only event we are interested in is when the mouse button is clicked,
which consists of a pressing and releasing action. If the mouse button is not released, we are not
interested in performing the operation. If the mouse button is pressed, it does not necessarily
mean that the user released the mouse button, so the answer in B is incorrect. The answer in E is
incorrect because we have not checked to see what region the mouse entered or exited.
For the next questions, consider the following class definition:
public class Q26_27
{
private int x;
public Q26_27(int newValue)
{
x = newValue;
}
}
26) Which of the following is true about the class Q26_27?
A) It has no parent class
B) Its parent class is Object
C) Its parent class is Java
D) It can not be extended
E) It has a default child called Object
27) If q1 and q2 are objects of Q26_27, then q1.equals(q2)
A) is a syntax error since equals is not defined in the Q26_27 class
B) is true if q1 and q2 both store the same value of x
C) is true if q1 and q2 reference the same Q26_27 object
D) is never true
E) throws a NullPointerException