Menu
Topics Index
...
`

Interfaces918


If you need explanation Read this topic

If you need Answer Take test on this topic

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

interface I2 extends I1
{
    void I2m2();
}

abstract class A extends I1, I2
{
    public void I2m2()
    {

    }

    public void I1m1()
    {

    }
}

abstract class B
{

}

class C extends A, I1, I2
{

}

class D extends A
{

}

A. A, B, C, D
B. A, C, D
C. B, C
D. B, 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.

Answer is B...
Interfaces is merely a collection of abstract methods which means they doesnt have body declared.
Interfaces can extend other interfaces
Abstract Class need not contain any methods.
Following the above rules,
If any class has abstract methods,then class has to be declared abstract,interfaces i1,i2 and Class B Compiles

say this is Rule 1) Abstract Classes can extend other classes but not interfaces, still it can implement interface like other classes do
say this is Rule 2) One class cannot extends multiple classes.only one class at max can be extended in Java

From our program,
Class A violates both Rules 1 and 2
class C violates Rules 1 and 2
Class D fails to compile for the same reason as class A

Posted by Shashanka Mogaliraju    2015-03-03 13:49:35


Ans is B..here we have the interfaces which contains the only abstract methods and by implementing the interfaces into the classes we will define the methods in the interface..
* a class can implement any num of interfaces and but class can't extend the interface
* if class does not override all methods in the interface than we must write that class as abstract
ClassA:
here class A extending the interfaces but class can't extend class must implement so here compiler will raise an error
No Problem with the class B
class C:
here class C extending the class A and extending the interfaces class can't extend the interfaces
if write the class A properly than no probelm with the class D

Posted by Uday Kumar    2015-03-04 03:02:08


This dose is now closed and the winners are Shashanka Mogaliraju,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Shashanka Mogaliraju for the 'Popular Comment'. The 'lucky liker' is Sonu Nagdev. 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-03-04 03:52:16


© meritcampus 2019

All Rights Reserved.

Open In App