0

can we override start() inside our custom thread class?

2nd Oct 2016, 4:11 AM
Vaibhav Kharche
Vaibhav Kharche - avatar
2 Antworten
+ 1
yes we can override stat() inside our custom Thread.!!! proof is the signature of the start() in Thread class signature is: public void start(){ } as the method is public we can override it. example: class MyThread extends Thread{ public void run(){ for(int i=0; i<=20; i++) System.out.println("custom Thread: "+i); } public void start(){ System.out.println("calling start() of Thread class from start() of MyThread class"); super.start(); //call to Thread class start() } public static void main(String[] args){ MyThread mt = new MyThread(); mt.start(); //call to local start() i.e. MyThread for(int i=0; i<=20; i++) System.out.println("main Thread: "+i); } }
2nd Oct 2016, 7:12 PM
Vaibhav Kharche
Vaibhav Kharche - avatar
0
no. override run()
2nd Oct 2016, 5:20 AM
Mythos