Interface vs Abstract class

  • June 3, 2022
  • Java
java thread class

As we all know, abstraction refers to hiding the internal implementation of a feature and only giving the users the functionality. i.e. how it works (showing), what it does (showing) (hiding). Because an abstraction is achieved using both abstract classes and interfaces, Interface and Abstract classes are needed prerequisites. Let’s see the differences between them.

Interface vs Abstract class
PropertiesInterfaceAbstract Class
Type of methods:An interface can have only abstract methods.An abstract class can have abstract and non-abstract methods. From Java 8, it can have default and static methods also.
Final Variables:Variables declared in a Java interface are by default final.An abstract class may contain non-final variables.
Type of variables: The interface has only static and final variables.An abstract class can have final, non-final, static and non-static variables. 
Implementation: Interface can’t provide the implementation of an abstract class.An abstract class can provide the implementation of the interface.
Inheritance vs Abstraction:A Java interface can be implemented using the keyword “implements”An abstract class can be extended using the keyword “extends”.
Multiple implementations:An interface can extend to another Java interface only.An abstract class can extend another Java class and implement multiple Java interfaces.
Accessibility of Data Members: Members of a Java interface are public by default.A Java abstract class can have class members like private, protected, etc.

Note: also read about the Interface in Java

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Reply

Your email address will not be published. Required fields are marked *