L
lonelyplanet999
Hi,
When I run below code the output is
MyThread foo
New
===
MyThread bar baz
foo
bar
The first line "MyThread foo" is output by t.start(), the line
"MyThread bar baz" is output by t1.run() & t1.run("don't care this
string").
The line "foo" is output by t.run() while the line "bar" output by
t1.start().
If I want to run public void run(String s) method of MyThread from
instance t (with an implicit inner class), is that possible ? If so,
how ?
Tks
===============================
class MyThread extends Thread {
MyThread() {
System.out.print(" MyThread");
}
public void run() {
System.out.print(" bar");
}
public void run(String s) {
System.out.println(" baz");
}
}
public class Ch9q19a {
public static void main (String [] args) {
Thread t = new MyThread() {
public void run() {
System.out.println(" foo");
}
};
t.start();
t.run();
System.out.println("\nNew\n===");
MyThread t1 = new MyThread();
t1.run();
t1.run("don't care this string");
t1.start();
}
}
When I run below code the output is
MyThread foo
New
===
MyThread bar baz
foo
bar
The first line "MyThread foo" is output by t.start(), the line
"MyThread bar baz" is output by t1.run() & t1.run("don't care this
string").
The line "foo" is output by t.run() while the line "bar" output by
t1.start().
If I want to run public void run(String s) method of MyThread from
instance t (with an implicit inner class), is that possible ? If so,
how ?
Tks
===============================
class MyThread extends Thread {
MyThread() {
System.out.print(" MyThread");
}
public void run() {
System.out.print(" bar");
}
public void run(String s) {
System.out.println(" baz");
}
}
public class Ch9q19a {
public static void main (String [] args) {
Thread t = new MyThread() {
public void run() {
System.out.println(" foo");
}
};
t.start();
t.run();
System.out.println("\nNew\n===");
MyThread t1 = new MyThread();
t1.run();
t1.run("don't care this string");
t1.start();
}
}