Which two are true?

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?

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



Leave a Reply 14

Your email address will not be published. Required fields are marked *


Jetendra

Jetendra

Answer are only C and E. Runnable is not printed.

Martin

Martin

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();

Ray

Ray

Answer are only C and D.

manish purohit

manish purohit

compilation fail ==b’coz non static method start() cannot be referenced from a static context.
so all options are wrong.

hieu

hieu

good choice!

hieu

hieu

Start();// where?
complation erro!

Eloi

Eloi

C and E, with t.start(); in the main method

Tim

Tim

+1

Tim

Tim

But “r = new runnable() {” must also be changed to “r = new Runnable() {“.

Charles

Charles

C and D. in order to start a thread, it should be t.start() not just start()

Luiz

Luiz

My answer is C, E.

If start(); is replaced by t.start();
and r = new runnable() { is replaced by r = new Runnable() {

rl

rl

what is thread of execution?