Runnable interface

 class MyRunnable implements Runnable {

 int n;

 MyRunnable(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) {

 Thread t = new Thread(new MyRunnable(5));

 t.start();

 }

}


Comments

Popular posts from this blog

10. Vehicle and Car

Interface with Rectangle

Multiple interface