Test#2MC portion 26 questions- 2points each. Total 50 points (1 question is extra credit). Take your time. Only first submission will be graded.

Reference classes here

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
For the question(s) below, assume values is an int array that is currently filled to capacity, with the following values:

1)  What is returned by values[3]? 1)
  A)  3
  B)  6
  C)  2
  D)  9
  E)  12

2)  What is the value of values.length? 2)
  A)  7
  B)  6
  C)  0
  D)  18
  E)  5

3)  Which of the following loops would adequately add 1 to each element stored in values? 3)
  A)  for(j=1;j<values.length-1;j++) values[j]++;
  B)  for(j=0;j<values.length;j++) values[j]++;
  C)  for(j=0;j<=values.length;j++) values[j]++;
  D)  for(j=0;j<values.length-1;j++) values[j]++;
  E)  for(j=1;j<values.length;j++) values[j]++;

4)  The statement System.out.println(values[7]); will 4)
  A)  cause an ArrayOutOfBoundsException to be thrown
  B)  output 7
  C)  output 18
  D)  output nothing
  E)  cause a run-time error

5)  After the following code, what will be the value of y (assume EasyInt is a class that models ints)

public void update (EasyInt x)
EasyInt y=new EasyInt(4);

  A)  4
  B)  5
  C)  8
  D)  9
  E)  this code wont compile because of null pointer exception..

6)  Which of the following is NOT an example of a static method? 6)
  A) random of the Math class
  B) getting the MAX_VALUE from the Integer class. This is not the answer. We havent talked about this yet, but Integer.MAX_VALUE is a static variable that gives the highest possible number an int can be..
  C) length of the String class
  D) sqrt of the Math class
  E) the public static void main method in every class that is automatically run.

7)  To define a class that will represent a car, which of the following definitions is most appropriate? 7)
  A)  public class CAR
  B)  private class Car
  C)  private class car
  D)  public class Car
  E)  public class car

8)  If a method does not have a return statement, then 8)
  A)  it can not be called from outside the class that defined the method
  B)  it must be defined to be a public method
  C)  it must be an int, double, or String method
  D)  it must be a void method
  E)  it will produce a syntax error when compiled

9)  A class' constructor usually defines 9)
  A)  how an object is initialized
  B)  if the instance data are accessible outside of the object directly
  C)  the number of methods in the class
  D)  how an object is interfaced
  E)  the number of instance data in the class

10)  Having multiple class methods of the same name where each method has a different number of or type of parameters is known as 10)
  A)  encapsulation
  B)  information hiding
  C)  importing
  D)  method overloading
  E)  tokenizing

(disregard the decimal format info - it is irrelevant)

11)  Which of the following could be used to instantiate a new Student s1? 11)
  A)  s1 = new Student( );
  B)  Student s1 = new Student("Jane Doe", "Computer Science", 3.333, 33);
  C)  new Student s1 = ("Jane Doe", "Computer Science", 3.333, 33);
  D)  new Student(s1);
  E)  Student s1 = new Student( );

12)  12)
  A)  s1 = getClassRank( );
  B)  getClassRank(s1);
  C)  s1.getClassRank( );
  D)  s1.toString( );
  E)  s1.getHours( );

13)  Another method that might be desired is one that updates the Student's number of credit hours. This method will receive a number of credit hours and add these to the Student's current hours. Which of the following methods would accomplish this? 13)
  A)  public void updateHours( )
  B)  public int updateHours( )
return hours;
  C)  public updateHours(int moreHours)
+= moreHours;
  D)  public void updateHours(int moreHours)
+= moreHours;
  E)  public int updateHours(int moreHours)
return hours
+ moreHours;

14)  The instruction Die d = new Die(10); results in 14)
  A)  The Die d having numFaces = 6 and faceValue = 10
  B)  The Die d having numFaces = 10 and faceValue = 1
  C)  The Die d having numFaces = 6 and faceValue = 1
  D)  A syntax error
  E)  The Die d having numFaces = 10 and faceValue = 10

15)  The instruction Die d = new Die(10, 0); results in 15)
  A)  The Die d having numFaces = 6 and faceValue = 10
  B)  The Die d having numFaces = 6 and faceValue = 1
  C)  A syntax error
  D)  The Die d having numFaces = 10 and faceValue = 1
  E)  The Die d having numFaces = 10 and faceValue = 10

16)  If the instruction Swapper s = new Swapper(0, "hello", 0); is executed followed by s.toString( ); what value is returned from s.toString( )? 16)
  A)  "00"
  B)  "hello"
  C)  0
  D)  "hello00"
  E)  "0"

17)  Which of the following criticisms is valid about the Swapper class? 17)
  A)  The instance data y is visible outside of Swapper
  B)  The instance data x is visible outside of Swapper
  C)  The instance data z is visible outside of Swapper
  D)  All 3 instance data are visible outside of Swapper
  E)  none of the methods are visible outside of Swapper

18)  If we have Swapper r = new Swapper (5, "no", 10); then r.swap( ); returns which of the following? 18)
  A)  "no510"
  B)  "15"
  C)  "no"
  D)  nothing
  E)  "510"

19)  Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal? 19)
  A)  foo(0, 0.1);
  B)  foo(0 / 1, 2 * 3);
  C)  foo(0);
  D)  foo( );
  E)  foo(1 + 2, 3 * 0.1);


Consider a method defined with the header:

public void doublefoo(double x). Which of the following method calls is legal?

  A)  doublefoo(0);
  B)  doublefoo(0.555);
  C)  doublefoo(0.1 + 0.2);
  D)  doublefoo(0.1, 0.2);
  E)  all of the above are legal except for D

For the question(s) below, consider a class that stores 2 int values. These values can be assigned int values with the messages set1(x) and set2(x) where x is an int, and these values can be accessed through get1( ) and get2( ). Assume that y and z are two objects of this class. The following instructions are executed:
z.set2(y.get1( ));
= z;
21)  The statement z.get2( ); will 21)
  A)  return 6
  B)  return 0
  C)  cause a run-time error
  D)  return 5
  E)  return 3

22)  If the instructions z.set2(5); and y.set1(10); are performed (after the previous instructions), which of the following is true? 22)
  A)  (y =  = z) is still true
  B)  (y.get1( ) =  = z.get1( )) but (y.get2( ) != z.get2( ))
  C)  (y.get1( ) =  = z.get2( )) and (y.get2( ) =  = z.get1( )) but (y != z)
  D)  this statement causes a run-time error
  E)  (y.get1( ) =  = z.get1( )) and (y.get2( ) =  = z.get2( )) but (y != z)

23)  What is the value of z after the third statement executes below?
StaticExample a
= new StaticExample(5);
StaticExample b
= new StaticExample(12);
int z
= a.incr( );
  A)  12
  B)  6
  C)  13
  D)  5
  E)  none, the code is syntactically invalid because a and b are attempting to share an instance data

24)  If there are 4 objects of type StaticExample, how many different instances of x are there? 24)
  A)  0
  B)  1
  C)  3
  D)  4
  E)  There is no way to know since any of the objects might share x, but they do not necessarily share x

25)  In Java, arrays are 25)
  A)  objects
  B)  Strings
  C)  interfaces
  D)  primitive data types if the type stored in the array is a primitive data type and objects if the type stored in the array is an object
  E)  primitive data types

26)  What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0.
< temp) c++;
  A)  It finds the smallest value and stores it in temp
  B)  It finds the largest value and stores it in temp
  C)  It sorts the values in list to be in ascending order
  D)  It counts the number of elements equal to the smallest value in list
  E)  It counts the number of elements in list that are less than temp