Menu
Topics Index
...
`

Interfaces Using Extends


If you need explanation Read this topic

If you need Answer Take test on this topic

Interfaces Using Extends
What will be the output of the following program?
public class Example {

    public static void main(String args[]) {
        Area a = new Area();
        a.area1();
        a.area2();
    }
}

interface C {

    int side = 4;

    void area1();
}

interface D extends C {

    double length = 3.5;
    double breadth = 4.5;

    void area2();
}

class Area implements D {

    public void area1() {
        System.out.println(side * side);
    }

    public void area2() {
        System.out.println(length * breadth);
    }
}

A. 16
15.0
B. 16
15.75
C. Some other output
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.

Ans is B..area1() is called and 4*4=16 is printed then area2() is called which prints 3.5*4.5=15.75

Posted by Badam Swathi    2014-06-30 08:40:36


ans b.
class area using interface d,
area1() method needs value frm intrface c,
so interfc D inherits C.
side value usd fr calcultn n prints 16.
area2() length n breadth value r takn frm intrface D n ptints 15.75

Posted by Maheshwari Natarajan    2014-06-30 08:50:41


B

Posted by Rathod Ajay    2014-06-30 11:53:16


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

Posted by Merit Campus    2014-07-01 04:14:04


© meritcampus 2019

All Rights Reserved.

Open In App