import java.util.*; class A { int x,y,z; A() { Scanner s=new Scanner(System.in); System.out.println("Enter x,y Values : "); x=s.nextInt(); y=s.nextInt(); } } class ThDemo extends A implements Runnable { void add() { z=x+y; System.out.println("Addition is : "+z); } void sub() { z=x-y; System.out.println("Subtraction is : "+z); } public void run() { try { add(); Thread.sleep(2000); sub(); } catch(Exception e) { System.out.println(e); } } } public class Main { public static void main(String args[]) { ThDemo d=new ThDemo(); Thread t=new Thread(d); t.start(); } }
Enter x,y Values : 12 12
Addition is : 24
Subtraction is : 0