start():
- An instance method of Thread class.
- We must start the thread by invoking start() method on Thread object.
- start() method allocates independent memory to run thread logic.
Program to define 2 Custom thread and start from main thread:
class Default { public static void main(String[] args) { First f = new First(); Second s = new Second(); f.start(); s.start(); } } class First extends Thread { public void run() { for (int i=1 ; i<=100 ; i++) { System.out.println(“First : ” + i); } } } class Second extends Thread { public void run() { for (int i=1 ; i<=100 ; i++) { System.out.println(“Second : ” + i); } } } |