Menu
Question Index
...

What will be the output of the following program?

public class iProgram {

    public static void main(String[] iArgs) {
        iPad iPad = new iPad();
        iPad.iOS = 6;
        iPhone iPhone = new iPhone();
        System.out.print(iPad.iOS + "->");
        iPhone.iPad = iPad;
        iPhone.release();
        System.out.print(iPad.iOS + "->");
        iPhone.iPad = new iPad();
        iPhone.release();
        System.out.print(iPad.iOS + "->" + iPhone.iPad.iOS);
    }
}

class iPad {

    int iOS = 0;
}

class iPhone {

    iPad iPad;

    void release() {
        iPad.iOS++;
    }
}


6->7->1->1
6->7->7->1
6->6->6->6
Some other output or Compilation Error or Runtime Error

Doubts

Problems

Topic: Advanced Java Programming Concepts

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App