Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming / Difference Between Abstract Class and Interface

Difference Between Abstract Class and Interface

June 21, 2011 Posted by Indika

Abstract Class vs Interface

Abstract class and Interface are two object oriented constructs found in many object oriented programming languages like Java. Abstract class can be considered as an abstract version of a regular (concrete) class, while an interface can be considered as a means of implementing a contract. Abstract class is a class that cannot be initialized but can be extended. Interface is a type that has to be implemented by other classes. In Java, Abstract classes are declared using Abstract keyword, while the interface keyword is used to define an interface.

What is an Abstract Class?

Typically, Abstract classes, also known as Abstract Base Classes (ABC), cannot be instantiated (an instance of that class cannot be created). So, Abstract classes are only meaningful to have if the programming language supports inheritance (ability to create subclasses from extending a class). Abstract classes usually represent an abstract concept or entity with partial or no implementation. Therefore, Abstract classes act as parent classes from which child classes are derived so that the child class will share the incomplete features of the parent class and functionality can be added to complete them.

Abstract classes may contain Abstract methods. Subclasses extending an abstract class may implement these (inherited) Abstract methods. If the child class implements all such Abstract methods, it is a concrete class. But if it does not, the child class also becomes an Abstract class. What all this means is that, when the programmer nominates a class as an Abstract, she is saying that the class will be incomplete and it will have elements that need to be completed by the inheriting subclasses. This is a nice way to create a contract between two programmers, which simplifies tasks in software development. The programmer, who writes code to inherit, needs to follow the method definitions exactly (but of course can have her own implementation).

What is an Interface?

An interface is an abstract type that is used to specify a contract that should be implemented by classes, which implement that interface. The interface keyword is used to define an interface and Implements keyword is used for implementing an interface by a class (in Java programming language). Usually, an interface will only contain method signatures and constant declarations. Any interface that implements a particular interface should implement all methods defined in the interface, or should be declared as an abstract class. In Java, the type of an object reference can be defined as an interface type. But that object must either be null or should hold an object of a class, which implements that particular interface. Using Implements keyword in Java, you can implement multiple interfaces to a single class.

What is the difference between Abstract Class and Interface?

Abstract classes usually represent an abstract concept or an entity with partial or no implementation. On the other hand, an interface is an abstract type that is used to specify a contract that should be implemented by classes. Abstract classes should be inherited (or extended), while interfaces should be implemented. Abstract classes may contain abstract methods, whereas an interface should only contain abstract methods. Abstract classes can contain any variables, but Interfaces can only define constants. A class cannot inherit from more than one abstract class but can implement multiple interfaces. An Interface cannot implement another interface. However an interface can extend a class.

Related posts:

Difference Between Virtual and Abstract Difference Between Java and JavaScript Difference Between Procedures and Functions in Programming Difference Between JSF2 and Seam3 Difference Between Inheritance and Containership

Filed Under: Programming Tagged With: ABC, Abstract Base Classes, Abstract class, Abstract methods, concrete class, interface, Interface type, object oriented constructs

About the Author: Indika

Indika, BSc.Eng, MSECE Computer Engineering, PhD. Computer Science, is an Assistant Professor and has research interests in the areas of Bioinformatics, Computational Biology, and Biomedical Natural Language Processing.

Leave a Reply Cancel reply

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

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Ascorbate and Ascorbic Acid

Difference Between Ascorbate and Ascorbic Acid

Difference Between Associates Degree and Bachelors Degree

Difference Between Associates Degree and Bachelors Degree

Difference Between Supervised and Unsupervised Machine Learning

Difference Between Supervised and Unsupervised Machine Learning

Difference Between Blackberry and Boysenberry

Difference Between Bulbourethral Gland and Prostate Gland

Difference Between Bulbourethral Gland and Prostate Gland

Latest Posts

  • What is the Difference Between COPD and Lung Cancer
  • What is the Difference Between Silk and Cotton
  • What is the Difference Between Galactosemia and Lactose Intolerance
  • What is the Difference Between Glycosuria and Glucosuria
  • What is the Difference Between Menkes and Wilson’s Disease
  • What is the Difference Between Xerophthalmia and Keratomalacia
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018 Difference Between. All rights reserved. Terms of Use and Privacy Policy: Legal.