Thread by extending thread

 class MyThread extends Thread {

 int n;

 MyThread(int n) {

 this.n = n;

 }

 public void run() {

 for (int i = 1; i <= n; i++) {

 System.out.println(i);

 }

 }

 public static void main(String[] args) {

 MyThread t = new MyThread(5);

 t.start();

 }

}


Comments

Popular posts from this blog

10. Vehicle and Car

Interface with Rectangle

Multiple interface