Menu
Question Index
...

What will be the output of the following program?

class Product {
    public static void main(String[] args) {
        new M().product(3);
        new N().product(3);
        new O().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) * i;
        System.out.print("( " + i + " = " + result + " ) ");
        return result;
    }
}


{ 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 ] ( 3 = 243 )
{ 3 = 9 } { 3 = 9 } ( 3 = 27 ) { 3 = 9 } { 3 = 9 } [ 3 = 81 ]
Compilation Error
Run-time 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