1.
Given:
1. public class Threads3 implements Runnable {
2. public void run() {
3. System.out.print(running);
4. }
5. public static void main(String[] args) {
6. Thread t = new Thread(new Threads3());
7. t.run();
8. t.run();
9. t.start();
10. }
11.}
What is the result?
2.
Given: public class NamedCounter { private final String name; private int count; public NamedCounter(String name) { this.name = name; } public String getName() { return name; } public void increment() { count++; } public int getCount() { return count; } public void reset() { count = 0; } } Which three changes should be made to adapt this class to be used safely by multiple threads? (Choose three.)
3.
Given:
1. public class TestSeven extends Thread {
2. private static int x;
3. public synchronized void doThings() {
4. int current = x;
5. current++;
6. x = current;
7. }
8. public void run() {
9. doThings();
10. }
11.}
Which statement is true?
4.
Given:
public class Yikes {
public static void go(Long n) {
System.out.print(Long );
}
public static void go(Short n) {
System.out.print(Short );
}
public static void go(int n) {
System.out.print(int );
}
public static void main(String[] args) {
short y = 6;
long z = 7;
go(y);
go(z);
}
}
What is the result?
5.
Given:
12. Date date = new Date();
13. df.setLocale(Locale.ITALY);
14. String s = df.format(date);
The variable df is an object of type DateFormat that has been initialized in line 11.
What is the result if this code is run on December 14, 2000?
6.
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)
7.
Given that c is a reference to a valid java.io.Console object, and:
11. String pw = c.readPassword(%s, pw: );
12. System.out.println(got  + pw);
13. String name = c.readLine(%s, name: );
14. System.out.println( got , name);
If the user types fido when prompted for a password, and then responds bob when prompted for a name, what is the result?
8.
Given:
11. String test = This is a test;
12. String[] tokens = test.split(\s);
13. System.out.println(tokens.length);
What is the result?
9.
Given:
import java.io.*;
class Animal {
Animal() {
System.out.print(a);
}
}
class Dog extends Animal implements Serializable {
Dog() {
System.out.print(d);
}
}
public class Beagle extends Dog {
}
If an instance of class Beagle is created, then Serialized, then deSerialized, what is the result?
10.
Given:
11. double input = 314159.26;
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);
13. String b;
14. //insert code here
Which code, inserted at line 14, sets the value of b to 314.159,26?