Menu
Topics Index
...
`

Adbul Kalam


If you need explanation Read this topic

If you need Answer Take test on this topic

Adbul Kalam
What will be the output of the following program?
public class AbdulKalam {
    int kalam = 0; int abdul = 14;
    public static void main(String[] args) {
        AbdulKalam ak = new AbdulKalam();
        Abdul a = new Abdul();
        a.process(ak);
        a.kalam.abdul.kalam.abdul.kalam.abdul.kalam.abdul.kalam.process(ak);
    }
    boolean isValid() { return kalam < abdul; }
}
class Abdul {
    Kalam kalam;
    void process(AbdulKalam ak) {
        if (ak.isValid()) {
            ak.kalam++;
            System.out.print("K" + ak.kalam);
            kalam = new Kalam();
            kalam.abdul = this;
            kalam.process(ak);
        }
    }
}
class Kalam {
    Abdul abdul;
    void process(AbdulKalam ak) {
        if (ak.isValid()) {
            ak.abdul -= ak.kalam;
            System.out.print("A" + ak.abdul);
            abdul = new Abdul();
            abdul.kalam = this;
            abdul.process(ak);
        }
    }
}

A. K1A13K2A11K3A8K4A4
B. K1A14K2A13K3A11K4A8
C. K1A13K2A11K3A8K4A4
K1A14K2A13K3A11K4A8
D. Some other output or Compilation Error
E. Throws NullPointerException
Topic: Calling A Class From Another Class In Java

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.

A. is the answer. as ak.abdul gives  13 and next 11 bcz on decremention of value.so A is the answer.

Posted by Shabaaz Shaikz    2014-04-10 12:46:32


Ans is A. When ak object is passed to a.process, kalam value is less than abdul so kalam is incremented and K with 1 is printed. next a.kalam is invoked which prints A13 ( abdul = abdul - kalam). Next abdul object is invoked and prints K2 and so on.

Posted by Nikhil Sulibhavi    2014-04-10 12:48:41


ans d

Posted by Adithya Aleti    2014-04-10 12:54:59


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

Posted by Merit Campus    2014-04-11 04:27:26


ThanQ MC :-)

Posted by Shabaaz Shaikz    2014-04-11 12:35:31


© meritcampus 2019

All Rights Reserved.

Open In App