There are 2 approached to define a Thread
- By extending Thread class.
- By implementing Runnable interface.
- Among the 2 ways of defining a Thread, implements Runnable approach is always recommended.
- In the 1st approach our class should always extends Thread class there is no chance of extending any other class hence we are missing the benefits of inheritance.
- But in the 2nd approach while implementing Runnable interface we can extend some other class also. Hence implements Runnable mechanism is recommended to define a Thread.
Output:
main method
run method
or
main method
run method
Thanks..!!
No comments:
Post a Comment