Menu
Topics Index
...
`

Interfaces Using Extends2755


If you need explanation Read this topic

If you need Answer Take test on this topic

Interfaces Using Extends2755
What will be the output of following program?
interface two {

    int a = 10;

    void root();
}

interface three extends two {

    int b = 30;

    void multiplication();
}

class Multiplication implements three {

    public void root() {
        System.out.println(Math.rint(Math.sqrt(a)));
    }

    public void multiplication() {
        System.out.println(a * b);
    }
}

public class Calculation {

    public static void main(String args[]) {
        Multiplication m = new Multiplication();
        m.root();
        m.multiplication();
    }
}

A. 3
300
B. 3.0
300
C. 3.162
300
D. Compilation Error or Runtime Error
Topic: Extending Interface In Java (extends)

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.

answer is A because m.root returns rounded integer value and m.multiplication returns 300 since multiplication implements three and three extends two.

Posted by Shiva Goud    2014-04-21 08:31:24


ans : b
math.rint() gives 3.0
and the multiplication result is 300

Posted by Ananda Kumar    2014-04-21 08:32:40


Here Math.sqrt() returns the square root of a (i.e, 10) that is rounded appropriately, which is then passed to Math.rint(). Math.rint() returns the closest floating-point value to the result obtained through Math.sqrt() i.e, 3.0. multiplication() outputs 300. So, the answer is B.

Posted by Shaileshwar Sharma    2014-04-21 12:31:13


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

Posted by Merit Campus    2014-04-22 04:20:58


© meritcampus 2019

All Rights Reserved.

Open In App