Menu
Question Index
...

What will be the output of the following program?

public class GuessIt {
    public static void main(String[] args) {
        Guess g = new Guess();
        g.G();
        Guess.CantGuess.ICanGuess.Hai hai = null;
        hai.print();
    }
}
class Guess {
    protected void G() {
        CantGuess cg = new CantGuess();
    }
    class CantGuess {
        public CantGuess() {
            System.out.print("CAB");
        }
        ICanGuess icg = new ICanGuess();
        GetICanGuess gicg = new GetICanGuess();
        class ICanGuess {
            public ICanGuess() {
                System.out.print("BAC");
            }
            Hai h = new Hai();
            public class Hai {
                public Hai() {
                    System.out.print("CBA");
                }
                public void print() {
                    System.out.print("print");
                }
            }
        }
        class GetICanGuess {
            public GetICanGuess() {
                System.out.print("ABC");
            }
        }
    }
}


CBABACABCCAB
CABCBABACABC
ABCBACCABCBA
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Access Modifiers 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