1.
Consider the following declaration:
final double FEE = 0.50;
The value of the variable FEE cannot subsequently be altered in the program, and any attempt to do so will be caught by the compiler.
2.
The following lines of code will swap the contents of the integer variables x and y:
int z;
x=y;
y=z;
z=x;
3.
The expression !(a||b) is equivalent to (!a)&&(!b)
4.
When Java evaluates the boolean expression
(num >= 0 && num <= 100)
the final value of the expression is determined only after both sub-expressions (num >= 0, num <= 100) are evaluated.
5.
String word = “computer”;
System.out.println(word.substring(3,6));
The output of the code above would be: mpu
6.
After the following code is executed, the value of x is 4
int x = 7;
x += 4;
7.
The ________ of a variable is that section of the program in which the variable exists.
A. 
B. 
C. 
D. 
E. 
8.
A(n) ________ is a class method that is automatically called whenever an object of that class is created.
A. 
B. 
C. 
D. 
E. 
9.
Consider the following code segment:
String S = “ILoveJava”;
System.out.print(S.substring(1,5));
What is output when this code segment is executed?
A. 
B. 
C. 
D. 
E. 
10.
Assume x and y are String variables with x = “Smile” and y = null. The result of (x == y) is
A. 
B. 
C. 
D. 
E. 
11.
Assume x and y are String variables with x = “Smile” and y = null. The result of x.length( )+ y.length( ) is
A. 
B. 
C. 
D. 
E. 
12.
The following method determines whether any character occurs more than once in the given String. However, the method has a bug.
boolean ContainsDouble(String S ) {
int n;
for ( n=1; n < S.length( ); n++ ) {
if (S.charAt(0) == S.charAt(n))
return true;
}
return false;
}
For which of the following String parameters would method ContainsDouble correctly return the value true?
I. “dttd” II. “xxxx” III. “look”
A. 
B. 
C. 
D. 
E. 
13.
Assume that x and y are int variables with x = 8, y = 3, and a and d are char variables with a =‘c’ and d =‘D’, and examine the following conditions:
Condition 1: !(true && false)
Condition 2: (a != d || x != 8)
Condition 3: (x < y && x > 0)
Condition 4: (x > y || a == ‘D’ || d != ‘D’)
A. 
B. 
C. 
Only conditions 2 and 4 are true
D. 
Only condition 3 is false
E. 
All four conditions are false
14.
Consider the following method:
int boo (int x, int y) {
x -= 2; ++y;
return x * y;
}
Consider the following code:
int x = 7, y = -3, z;
z = x + y + boo ( y, x );
What is z?
A. 
B. 
C. 
D. 
E. 
15.
Consider the following code:
int b = 6;
int c = 11;
int a = b * (-c + 2) / 7;
The value stored in a is:
A. 
B. 
C. 
D. 
E. 
16.
Consider the following swap method.
public void sillyStrings(String a, String b) {
a = a + “One”;
b = b + a;
}
If String x = “Hello” and String y = “Goodbye”, then sillyStrings(x, y); results in which of the following?
A. 
X is now “HelloOne” and y is “GoodbyeHelloOne”
B. 
X is still “Hello” and y is now “HelloOne”
C. 
D. 
E. 
X is now “GoodbyeOne” and y is now “HelloGoodbyeOne”
17.
Consider a Point class with the following constructors and methods
instance data
description
private int myX
the current x coordinate
private int myY
the current y coordinate
Methods
description
Point ()
Default constructor:
Initialize the point to (0,0)
Point(int x, int y)
Another constructor:
Initialize the point to (x,y)
void SetX(int x)
Set the x coordinate to the given value
void SetY (int y)
Set the y coordinate to the given value
int GetX()
return the x coordinate
int GetY()
return the y coordinate
Which of the following code segments correctly defines a Point variable that represents the point 3,5?
Segment I
Point P();
P.myX = 3;
P.myY = 5;
Segment II
Point P();
P.SetX(3);
P.SetY(5);
Segment III
Point P(3,5);
A. 
B. 
C. 
D. 
E. 
18.
Consider a Point class with the following constructors and methods
instance data
description
private int myX
the current x coordinate
private int myY
the current y coordinate
Methods
description
Point ()
Default constructor:
Initialize the point to (0,0)
Point(int x, int y)
Another constructor:
Initialize the point to (x,y)
void SetX(int x)
Set the x coordinate to the given value
void SetY (int y)
Set the y coordinate to the given value
int GetX()
return the x coordinate
int GetY()
return the y coordinate
Assume that P is a Point object that represents the point x,y. Which code segment correctly changes P to represent y,x?
A)
P.SetX (P.GetY( ));
P.SetY (P.GetX( ));
B)
P.GetX( ) = P.GetY( );
P.GetY( ) = P.GetX( );
C
int tmp = P.myX;
P.myX = P.myY;
P.myY = tmp;
D)
int tmp = P.GetX( );
P.SetX(P.GetY( ) );
P.SetY(tmp);
A. 
B. 
C. 
D. 
19.
For questions 16 and 17, use the following class definition:
public class StaticExample {
private static int x;
public StaticExample (int y) {
x = y;
}
public int incr( ) {
x++;
return x;
}
}
16) What is the value of z after the third statement executes below?
StaticExample a = new StaticExample(12);
StaticExample b = new StaticExample(5);
int z = a.incr( );
A) 5
B) 6
C) 12
D) 13
E) The code is syntactically invalid
A. 
B. 
C. 
D. 
E. 
20.
Consider the following class
public class StaticExample {
private static int x;
public StaticExample (int y) {
x = y;
}
public int incr( ) {
x++;
return x;
}
}
If there are 4 objects of type StaticExample, how many different instances of x are there?
A. 
B. 
C. 
D. 
E.