Nathan Sprague
Spring 2021
spragunr
What will be printed when the following code segment executes?
Person bob = new Person("Bob");
Person jane = bob;
jane.setName("Jane");
System.out.println(bob.getName());
What will be printed when the following code segment executes?
String s1 = "Hello There!";
String s2 = "Hello";
String s3 = s2 + " There!";
if (s1 == s3) {
System.out.println(s1);
} else {
System.out.println(s2);
}
How many times will the body of the following for-loop be executed?
Assuming values
contains {3, 1, 4, 2}
, what will v
contain after the code segment below executes?
int v = values[0];
for (int i = 1; i < values.length; i++) {
if (v < values[i]) {
v = values[i];
}
}