Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package intropackage;
- public class Driver {
- public static void main(String[] args) throws InterruptedException {
- Display display = new Display();
- myThread thread = new myThread(display);
- myThread2 thread2 = new myThread2(display);
- thread.start();
- thread2.start();
- }
- }
- public class Display extends Thread {
- public void displayN()
- {
- for(int i=0;i<10;i++)
- {
- System.out.println(i);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- System.out.println("INTERRUPTED");
- }
- }
- }
- public void displayC()
- {
- for(int i=65;i<=75;i++)
- {
- System.out.println((char)i);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- System.out.println("INTERRUPTED");
- }
- }
- }
- }
- public class myThread extends Thread {
- Display ob;
- public myThread(Display ob) {
- this.ob=ob;
- }
- @Override
- public void run() {
- ob.displayN();
- }
- }
- public class myThread2 extends Thread {
- Display ob;
- public myThread2(Display ob) {
- this.ob=ob;
- }
- @Override
- public void run() {
- ob.displayC();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement