Menu
Topics Index
...
`

Interfaces


If you need explanation Read this topic

If you need Answer Take test on this topic

Interfaces
Which of the following classes fail to compile.
interface I1
{
    void m1();
}

interface I2 extends I1
{
    void m2();
}

abstract class A implements I1, I2
{
    public void m2()
    {

    }

    public void m()
    {

    }
}

abstract class B implements I2
{

}

class C extends A implements I1, I2
{

}

class D extends A
{

}

A. A, B, C, D
B. B, C, D
C. B, C
D. C, D
E. All of them compile
Topic: Creating Interface In Java With Example Program

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 D..here we have the Interfaces Concept interface is an blue print of the Class where class can contain abstract methods and normal methods but interface will contain only abstract methods and constant variables and interfaces dont have constructors..
Execution:
here we have the 2 interfaces I1 and I2 where I1 is the Parent interface and I2 is the Child interface..so I2 inherit the m1() from the I1
Coming to the classes class A implementing I1 and I2 so it will have now the m1() and m2() as abstract methods but it overrides the m2() with normal method but it has m1() as abstract method and class made as abstract so no problem with A
class B implementing the I2 but didnot override the m1() m2() so class made as abstract so no problem with B
class C is Extending A and implementing the i1 and i2 here in this now we have the m1() m2() as abstract methods but we will inherit the m2() normal method from the class A so now we will have m1() as abstract method and did not write class as abstract so here compiler will raise an error
class D extending the class A so in class we have m1() as abstract method it will inherit into the class D but class D is not abstract so here compiler will raise an error

Posted by Uday Kumar    2015-02-12 04:37:12


d

Posted by Shubham Bansal    2015-02-13 03:16:24


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Maheshwari Natarajan. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-02-13 03:17:32


© meritcampus 2019

All Rights Reserved.

Open In App