Menu
Question Index
...

What will be the output of the following program?

public class Mummy {
    public static void main(String[] args) {
        Daddy d = new Daddy();
        String result = "";
        int i = 0;
        result += Daddy.Son("20");
        i++;
        result += d.Daughter();
        i++;
        d.Child(i);
        i++;
        result += GrandFather.Son(result);
        System.out.print(i + " - " + result);
    }
}
class GrandFather extends Daddy {
    public String Son() {
        String hai = "Good Morning";
        Daddy.Son(hai);
        return "";
    }
}
class Daddy {
    public static String Son(String str) {    return "I am " + str + " years old, ";    }
    public String Daughter() {
        String str = Son("25");
        str += "I am 24 years old, ";
        return str;
    }
    public void Child(int i) {
        i++;
        String str = "I am child, ";
    }
}


Some other output
4 - I am 20 years old I am 25 years old I am 24 years old I am 20 years old I am 25 years old Good Morning
3 - I am 25 years old
 I am 25 years old
 I am 24 years old
 I am 25 years old
4 - I am 20 years old
 I am 25 years old
 I am 24 years old
 I am child
 I am I am 20 years old
 I am 25 years old
 I am 24 years old
  I am Good Morning years old
3 - I am 25 years old I am 25 years old I am 24 years old I am 25 years old
Compilation Error or Runtime Error

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App