Menu
Question Index
...

What will be the output of the following program?

class Product {
    public static void main(String[] args) {
        M m = new M();    M n = new N();
        M o = new O();    O oo = new O();
        m.product(3);    n.product(3);
        oo.product(3);
    }
}
class M {
    int product(int i) {
        int result = i * i;
        System.out.print("{" + i + ", " + result + "}~");
        return result;
    }
}
class N extends M {
    int product(int i) {
        int result = super.product(i) * super.product(i);
        System.out.print("[" + i + ", " + result + "]~");
        return result;
    }
}
class O extends M {
    int product(int i) {
        int result = super.product(i) * super.product(i);
        System.out.print("(" + i + ", " + result + ")~");
        return result;
    }
}


{3, 9}~[3, 9]~(3, 9)~
{3, 9}~[3, 9]~{3, 9}~(3, 27)~
{3, 9}~{3, 9}~{3, 9}~[3, 81]~{3, 9}~(3, 27)~
{3, 9}~{3, 9}~{3, 9}~[3, 81]~{3, 9}~{3, 9}~(3, 81)~
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Super Keyword In Java To Call Super Class Constructor

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App