you can create a Thread in java with two different ways
1)by extending from Thread class
public class MyThread extends Thread {
public void run() {
System.out.println("This is Thread");
}
public static void main(String[] args) {
Thread thread = new MyThread();
thread.start();
}
}
2) by implementing runnable
public class MyRunnable implements Runnable {
public void run() {
System.out.println("this is Thread");
}
public static void main(String[] args) {
Thread thread = new Thread(new MyRunnable());
thread.start();
}
}
No comments:
Post a Comment