Menu
Question Index
...

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);
        }
    }
}


K1A13K2A11K3A8K4A4
K1A14K2A13K3A11K4A8
K1A13K2A11K3A8K4A4
K1A14K2A13K3A11K4A8
Some other output or Compilation Error
Throws NullPointerException

Doubts

Problems

Topic: Calling A Class From Another Class In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App