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;
        return result;
    }
}

interface N
{
    int product(int i);
}

class O extends M implements N
{
    int product(int i)
    {
        int result = super.product(i) * i;

        System.out.println("In O class  =  " + super.product(i) * i);
        return result;
    }
}

class P extends M
{
    public int product(int i)
    {
        int result = super.product(i) + i;

        System.out.println("In P class = " + result);
        return result;
    }
}


In O class = 27
In P class = 30
In O class = 27
In P class = 12
Compilation Error
Run-time Error

Doubts

Problems

Topic: Access Modifiers 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