Try it here
Subscribe
Interface and Abstract

Interface and Abstract Class After Java 8

interface_and_abstract_class_after_java_8

With the introduction of concrete methods (default and static methods) to interfaces from Java 8, the gap between interface and abstract class has been reduced significantly. Now both can have concrete methods as well as abstract methods. But, still there exist some minute differences between them. In this article, we will try to list down the differences between interface Vs abstract class after Java 8.

Differences Between Interface And Abstract Class After Java 8 :

  1. Fields

    Interface fields are public, static and final by default. Interfaces still don’t support non-static and non-final variables. Interfaces can only have public, static and final variables. On the other hand, abstract class can have static as well as non-static and final as well as non-final variables. They also support private and protected variables along with public variables.

  2. Methods

    After Java 8, an interface can have default and static methods along with abstract methods. Interfaces don’t support final methods. But, abstract classes support final as well as non-final methods and static as well as non-static methods along with abstract methods.

    Also note that, only interfaces can have default methods. Abstract classes can’t have default methods.

  3. Constructors

    Interfaces can’t have constructors. Abstract classes can have any number of constructors.

  4. Member’s Accessibility

    All members of interfaces are public by default. Interfaces don’t support private and protected members. But, abstract classes support all type of members – private, protected and public members.

  5. Multiple Inheritance

    A class can extend only one abstract class, but can implement multiple interfaces. Thus, a class can inherit multiple properties from multiple sources only through interfaces, not through abstract classes.

Writer profile pic

Devbarma on Apr 17, 2015 at 12:04 am


This article is contributed by Devbarma. If you like dEexams.com and would like to contribute, you can write your article here or mail your article to admin@deexams.com . See your article appearing on the dEexams.com main page and help others to learn.



Post Comment

Comments( 0)

WEB TECHNOLOGY
×

Forgot Password

Please enter your email address below and we will send you information to change your password.