Menu
Question Index
...

What will be the output of the following program?

class Desktop extends TSystem {
    public String getString() {
        Laptop l = new Laptop();
        str += l.getString();
        return str + "Hello";
    }
}

class Laptop extends TSystem {
    public String getString() {
        return "Welcome";
    }
}

public class TSystem {
    static String str = "";
    public String getString() {
        Desktop d = new Desktop();
        str += d.getString();
        return str + "Hai";
    }
    public static void main(String[] args) {
        TSystem ts = new TSystem();
        str += ts.getString();
        System.out.println(str);
    }
}


HaiHelloWelcome
WelcomeHelloHai
HelloHaiWelcome
HaiWelcomeHello
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Static Keyword 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