Creating Threads by Extending Thread Class in Java


public class Users {
    public static void main(String[] args) {
        AppleA a = new AppleA();
        AppleB b = new AppleB();
        a.start();
        b.start();
    }
}

class AppleA extends Thread {

    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("AppleA " + i);
        }
        System.out.println("Exit AppleA");
    }
}

class AppleB extends Thread {

    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("ClassB " + i);
        }
        System.out.println("Exit B");
    }
}

Output:

Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment