Menu
Topics Index
...
`

Interfaces930


If you need explanation Read this topic

If you need Answer Take test on this topic

Interfaces930
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;
    }
}

A. In O class = 27
In P class = 30
B. In O class = 27
In P class = 12
C. Compilation Error
D. Run-time Error
Topic: Access Modifiers In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is C

Posted by Adithya Aleti    2014-04-17 10:03:43


answer is 'C' because we a calling product function which returns int but we r not catching it so gives error

Posted by Sai Teja    2014-04-17 11:18:55


Ans is C...we are implementing the N interface..so v shud overide that method as pubic.here v are nt specyng..it wl tak as default

Posted by Uday Kumar    2014-04-17 12:41:02


Congratulations Sai Teja. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-18 04:19:48


© meritcampus 2019

All Rights Reserved.

Open In App