Given:
public class SuperThread extends Thread {
public void run(String name) {
System.out.print(“Thread”);
}
public void run(Runnable r) {
r = new runnable() {
public void run() {
System.out.print(“Runnable”);
}
};
}
public static void main(String[] args) {
Thread t = new SuperThread();
start();
}
}
Which two are true?
A.
Thread is printed
B.
Runnable is printed
C.
No output is produced
D.
No new threads of execution are started within the main method
E.
One new thread of execution is started within the main method
F.
Two new threads of exclusion are started within the main method
Answer are only C and E. Runnable is not printed.
You are right. Thread.run() have no parameter. So the run(String) and run (Runnable) didn’t overwrite the method. Means no output is written… but the thread is starting if there stands t-start() and not only start();
Answer are only C and D.
compilation fail ==b’coz non static method start() cannot be referenced from a static context.
so all options are wrong.
good choice!
C E
Start();// where?
complation erro!
C and E, with t.start(); in the main method
+1
But “r = new runnable() {” must also be changed to “r = new Runnable() {“.
C and D. in order to start a thread, it should be t.start() not just start()
My answer is C, E.
If start(); is replaced by t.start();
and r = new runnable() { is replaced by r = new Runnable() {
what is thread of execution?
ce