Menu
Topics Index
...
`

Threads2018


If you need explanation Read this topic

If you need Answer Take test on this topic

Threads2018
What will be the output of the following program?
public class Kashmir {
    public static void main(String[] args) {
        try {
            KanyaKumari kk = new KanyaKumari();
            kk.run();
            p('A');
            kk.start();
            kk.join();
            p('H');
            kk.run();
            p('M');
            kk.start();
            p('B');
        } catch (Exception ex) {
            p('I');
        }
        p('R');
    }
    private static void p(char c) {
        System.out.print(c);
    }
}
class KanyaKumari extends Thread {
    String s = "KSMI";
    static int i = 0;
    public void run() {
        System.out.print(s.charAt(i++));
    }
}

A. KASHMMIBR
B. KASHMMIR
C. KAHSMIRM
D. Output can not be determined
E. Compilation Error or Runtime Error
Topic: What is Multitasking and Multithreading?

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

E.cmpilation error happens..in kanyakumari object.

Posted by Shabaaz Shaikz    2013-12-12 12:44:26


Answer is B :: initially i point to 0 and hence K is printed when run is called...thne A is passed..nw i points to 1 n thus takes 'S'..then 'H' is joined...nw i is incremntd n is pointed to 2 that is to 'M' then again 'M' is passed ...excpetion is throwed,will be catched in catch block..prints 'I'..thn cums out and prints 'R'...

Posted by Shaik Nyamath    2013-12-12 13:10:11


Congratulations Shaik Nyamath. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-12-13 03:58:36


© meritcampus 2019

All Rights Reserved.

Open In App