Topics Index

Interfaces and Classes

If you need explanation Read this topic

If you need Answer Take test on this topic

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

interface I2 extends I1 {
    void m2();

abstract class A implements I1 {
    public void m1() {}
    public void m2() {}

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
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 we have the interfaces and abstract classes concept..
abstract class is an class which contains the abstract methods and normal methods...we cant create instance for the abstract class..
interface: it is a container which contains the all abstract methods..of abstract class has all abstract methods than we can write that as interface..

here we have 2 interfaces.. I1 n I2. i2 extending the i1 so it will have the m1() and m2() so no problem with these 2 interfaces..

class A implementing the I1..and these class is overriding the m1() which is there in the I1 and writing another method with name m2() A is abstract..even if it is not abstract no problem Bcz A did not contain any abstract methods..

class B implementing the I2 so it will get m1() m2() both abstract methods will come into B and B is made abstract so np must made abstract if not error...

class C extending the A and implementing the I1 n I2 so here from it will get m1() and m2() so abstract methods will get need to make abstract..

class D extending the A so it will get m1() n m2() so Np Problem with these class

Posted by Uday Kumar    2014-12-10 12:11:05

ans e

An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements.

Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.

The interface keyword is used to declare an interface

When a class implements an interface, you can think of the class as signing a contract, agreeing to perform the specific behaviors of the interface. If a class does not perform all the behaviors of the interface, the class must declare itself as abstract.

A class uses the implements keyword to implement an interface.

An interface can extend another interface, similarly to the way that a class can extend another class. The extends keyword is used to extend an interface, and the child interface inherits the methods of the parent interface.

A Java class can only extend one parent class. Multiple inheritance is not allowed. Interfaces are not classes, however, and an interface can extend more than one parent interface.

The extends keyword is used once, and the parent interfaces are declared in a comma-separated list.

coming to this program we ve 2 interface ,2 abstract classes,2 classes.

here interface i2 extends i1.
Abstract class A implements I1 interface ,abstract class B implements I2 interface.

class c extends class A implements both interface,

class D extends class A

all these access are legal and compiled successfully

Posted by Maheshwari Natarajan    2014-12-10 13:56:39


Posted by Shubham Bansal    2014-12-10 15:47:05

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 to raise the recharge.

Posted by Merit Campus    2014-12-11 05:34:07

© meritcampus 2019

All Rights Reserved.

Open In App