Prerequisite Challenge Exam Sample Questions for CS 111C / CS 270

1. What is true given the following code:

char[] array1 = {'j', 'a', 'v', 'a'};
char[] array2 = array1;
array2[2] = 'b';
  1. array1[2] has the value 'j'
  2. array1[2] has the value 'a'
  3. array1[2] has the value 'v'
  4. array1[2] has the value 'b'

2. What is displayed when the following program is executed?

public class CanYouDoIt {
  public static void main (String[] args) {
    int way[] = {1, 2, 3, 4};
    callIt(way);
    System.out.println(way[1] + way[2]);
  }
  public static void callIt(int myWay[]) {
    myWay[1] = myWay[3];
  }
}
  1. 3
  2. 5
  3. 6
  4. 7
  5. none of the above

Answers: 1-d, 2-d

Return to the CCSF Computer Science Department Home Page