Menu
Question Index
...

What will be the output of the following program?

class OutPut
{
    public static void main(String[] args)
    {
        new M().product(3);
        new O().product(3);
        new P().product(3);
    }
}

class M
{
    int product(int i)
    {
        int result = i * i;
        System.out.print(" M = " + result + ",");
        return result;
    }
}

interface N
{
    public int product(int i);
}

class O extends M implements N
{
    public int product(int i)
    {
        int result = super.product(i) * i;
        System.out.print(" O = " + result + ",");
        return result;
    }
}

class P extends O
{
    public int product(int i)
    {
        int result = super.product(i) + i;
        System.out.print(" P = " + result);
        return result;
    }
}


M = 9, M = 9, O = 27, M = 9, O = 27, P = 30
M = 9, O = 27, P = 30
M = 9, M = 9, O = 27, M = 9, O = 81, P = 84
M = 9, O = 27, O = 81, P = 84
Compilation Error

Doubts

Problems

Topic: Creating Interface In Java With Example Program

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App