Given:
1. public class Threads4 {
2. public static void main (String[] args) {
3. new Threads4().go();
4. }
5. public void go() {
6. Runnable r = new Runnable() {
7. public void run() {
8. System.out.print("foo");
9. }
10. };
11. Thread t = new Thread(r);
12. t.start();
13. t.start();
14. }
15.}
What is the result?
Given:
1. public class Barn {
2. public static void main(String[] args) {
3. new Barn().go(hi, 1);
4. new Barn().go(hi, world, 2);
5. }
6. public void go(String... y, int x) {
7. System.out.print(y[y.length - 1] + );
8. }
9. }
What is the result?
Given:
1. class Nav{
2. public enum Direction { NORTH, SOUTH, EAST, WEST }
3. }
1. public class Sprite{
2. // insert code here
3. }
Which code, inserted at line 14, allows the Sprite class to compile?
Given:
1. public class Rainbow {
2. public enum MyColor {
3. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);
4. private final int rgb;
5. MyColor(int rgb) { this.rgb = rgb; }
6. public int getRGB() { return rgb; }
7. };
8. public static void main(String[] args) {
9. //insert code here
10. }
11.}
Which code fragment, inserted at line 19, allows the Rainbow class to compile?
1. public class Mud {
2. //insert code here
3. System.out.println(hi);
4. }
5. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String...[] a) {
How many of the code fragments, inserted independently at line 2, compile?
Given:
1. class Atom {
2. Atom() { System.out.print(atom ); }
3. }
4. class Rock extends Atom {
5. Rock(String type) { System.out.print(type); }
6. }
7. public class Mountain extends Rock {
8. Mountain() {
9. super(granite );
10. new Rock(granite );
11. }
12. public static void main(String[] a) { new Mountain(); }
13.} What is the result?
Given:
interface TestA { String toString(); }
public class Test {
public static void main(String[] args) {
System.out.println(new TestA() {
public String toString() { return test; }
});
}
}
What is the result?