java interface vs abstract class

Abstract Class vs. Interface
Java provides and supports the creation of abstract classes and interfaces. Both implementations share some common features, but they differ in the following features:

1.All methods in an interface are implicitly abstract. On the other hand, an abstract class may contain both abstract and non-abstract methods.

2.A class may implement a number of Interfaces, but can extend only one abstract class.

3.In order for a class to implement an interface, it must implement all its declared methods. However, a class may not implement all declared methods of an abstract class. Though, in this case, the sub-class must also be declared as abstract.

4.Abstract classes can implement interfaces without even providing the implementation of interface methods.

5.Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.

6.Members of a Java interface are public by default. A member of an abstract class can either be private, protected or public.
An interface is absolutely abstract and cannot be instantiated. An abstract class also cannot be instantiated, but can be invoked if it contains a main method.

One thought on “java interface vs abstract class


电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>