开发者

Difference between an abstract class and an interface? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Interface vs Base class

A class implementing an interface has to implement all the methods of the interface, but if that class is implementing an abstract开发者_StackOverflow class is it necessary to implement all abstract methods?

If not, can we create the object of that class which is implementing the Abstract class???


If you implement an abstract class and don't implement all the abstract methods, that class also has to be declared abstract, and therefore cannot be instantiated.

For example:

public abstract class A {

  public abstract method1();

}

public abstract class B extends A {

}

In the above example you would not be able to call new B();


If a class inherits an abstract class, it either has to implement all abstract members, or it has to be abstract too.

So, if the class doesn't implement all members, you can't create an instance of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜