public class TestOne implements Runnable {
public static void main (String[] args) throws Exception {
Thread t = new Thread(new TestOne());
t.start();
System.out.print(”Started”);
t.join();
System.out.print(”Complete”);
}
public void run() {
for (int i= 0; i< 4; i++) {
System.out.print(i);
}
}
}
What can be a result?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes and prints “StartedComplete”.
D. The code executes and prints “StartedComplete0123”.
E. The code executes and prints “Started0l23Complete”.
您可能感兴趣的试卷
你可能感兴趣的试题
public class TestOne {
public static void main (String[] args) throws Exception {
Thread.sleep(3000);
System.out.println(”sleep”);
}
}
What is the result?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes normally and prints “sleep”.
D. The code executes normally, but nothing is printed.
public class Threads2 implements Runnable {
public void nun() {
System.out.println(”run.”);
throw new RuntimeException(”Problem”);
}
public static void main(String[] args) {
Thread t = new Thread(new Threads2());
t.start();
System.out.println(”End of method.”);
}
}
Which two can be results?()
A. java.lang.RuntimeException: Problem
B. run. java.lang.RuntimeException: Problem
C. End of method. java.lang.RuntimeException: Problem
D. End of method. run. java.lang.RuntimeException: Problem
E. run. java.lang.RuntimeException: Problem End of method.
public class Starter extends Thread {
private int x= 2;
public static void main(String[] args) throws Exception {
new Starter().makeItSo();
}
public Starter() {
x=5;
start();
}
public void makeItSo() throws Exception {
join();
x=x- 1;
System.out.println(x);
}
public void run() { x *= 2; }
}
What is the output if the main() method is rum?()
A. 4
B. 5
C. 8
D. 9
E. Compilation fails.
F. An exception is thrown at runtime.
G. It is impossible to determine for certain.
Runnable r = new Runnable() {
public void run() {
System.out.print(”Cat”);
}
};
Threadt=new Thread(r) {
public void run() {
System.out.print(”Dog”);
}
};
t.start();
What is the result?()
A. Cat
B. Dog
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.
public class Threads5 {
public static void main (String[] args) {
new Thread(new Runnable() {
public void run() {
System.out.print(”bar”);
}
}).start();
}
}
What is the result?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes normally and prints “bar”.
D. The code executes normally, but nothing prints.
public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print(”foo”);
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
}
What is the result?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes normally and prints „foo”.
D. The code executes normally, but nothing is printed.
public class Threads3 implements Runnable {
public void run() {
System.out.print(”running”);
}
public static void main(String[] args) {
Thread t = new Thread(new Threads3());
t.run();
t.run();
t.start();
}
}
What is the result?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes and prints “running”.
D. The code executes and prints “runningrunning”.
E. The code executes and prints “runningrunningrunning”.
A. new Thread() { public void run() { doStuff(); } }
B. new Thread() { public void start() { doStuff(); } }
C. new Thread() { public void start() { doStuff(); } } .run();
D. new Thread() { public void run() { doStuff(); } } .start();
E. new Thread(new Runnable() { public void run() { doStuff(); } } ).run();
F. new Thread(new Runnable() { public void run() { doStuff(); } }).start();
12. String csv = “Sue,5,true,3”;
13. Scanner scanner = new Scanner( csv);
14. scanner.useDelimiter(”,”);
15. int age = scanner.nextInt();
What is the result?()
A. Compilation fails.
B. After line 15, the value of age is 5.
C. After line 15, the value of age is 3.
D. An exception is thrown at runtime.
System.out.format(”Pi is approximately %d.”, Math.PI);
What is the result?()
A. Compilation fails.
B. Pi is approximately 3.
C. Pi is approximately 3.141593.
D. An exception is thrown at runtime.
最新试题
Which two of statements are true?()
What is the result?()
Which three will compile and run without exception?()
What is the output if the main() method is run?()
What is the result?()
What is the result?()
Which statement is true?()
Given that Triangle implements Runnable, and:Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute?()
Which three changes should be made to adapt this class to be used safely by multiple threads?()
What is the result?()