Compare the Difference Between Similar Terms

Difference Between

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

Difference Between Abstract Class and Inheritance

June 22, 2011 Posted by Indika

Abstract Class vs Inheritance

Abstract class and Inheritance are two important object oriented concepts found in many object oriented programming languages like Java. Abstract class can be considered as an abstract version of a regular (concrete) class, while Inheritance allows new classes to extend other classes. Abstract class is a class that cannot be initialized but can be extended. So, Abstract classes are only meaningful to have if the programming language supports inheritance. In Java, Abstract classes are declared using Abstract keyword, while Extends keyword is used for inheriting from a (super) class.

What is  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 Inheritance?

Inheritance is an object oriented concept, which allows new classes to extend other classes. Extends keyword is used to implement the concept of inheritance in Java programming language. Inheritance essentially provides code reuse by allowing extending properties and behavior of an existing class by a newly defined class. When a new subclass (or derived class) extends a super class (or parent class) that subclass will inherit all attributes and methods of the super class. The subclass can optionally override the behavior (provide new or extended functionality to methods) inherited from the parent class. Typically, A subclass cannot extend multiple super classes (e.g. in Java). Therefore, you cannot use extends for multiple inheritance. In order to have multiple inheritance, you need to use interfaces.

What is the difference between Abstract Class and Inheritance?

Abstract classes usually represent an abstract concept or an entity with partial or no implementation. Inheritance allows new classes to extend other classes. Because, Abstract classes cannot be instantiated, you need to use the concept of inheritance to make use of Abstract classes. Otherwise, an Abstract class has no use. Abstract classes may contain Abstract methods and when the class is extended, all methods (Abstract and concrete) are inherited. The inherited class can implement any or all the methods. If all the Abstract methods are not implemented, then that class also becomes an Abstract class. A class cannot inherit from more than one Abstract class (this is not a quality of Abstract classes per se, but rather a restriction of inheritance).

Related posts:

Difference Between Abstract Class and Concrete Class Difference Between Virtual and Abstract Difference Between Abstract Class and Interface Difference Between Implements and Extends Difference Between Graph and Tree

Filed Under: Programming Tagged With: ABC, abstract, Abstract Base Classes, Abstract class, Abstract classes, Abstract keyword, Abstract methods, concrete class, Extends keyword, Inheritance, Inheritance class, inherited class, Java, multiple inheritance, object oriented concepts, regular class, super class

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.

Comments

  1. Jason says

    August 30, 2017 at 1:25 pm

    Thank you for explaining the difference. All my questions have been solved by this.

    Reply
  2. Aus says

    May 10, 2019 at 3:04 pm

    best answer on the web, Teacher aint explain shit and makes no sense, mono tone mf. This is how you explain concepts.

    Reply

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 Everyday and Every Day

Difference Between Everyday and Every Day

Difference Between Motorola Photon 4G and HTC Evo Design 4G

Difference Between Windows Phones HTC 7 Pro and HTC 7 Trophy

Difference Between Salsa and Samba

Difference Between Salsa and Samba

Difference Between Socket and Port

Latest Posts

  • What is the Difference Between Penta and Hexa Vaccine
  • What is the Difference Between Vital and Supravital Staining
  • What is the Difference Between Post Transcriptional and Post Translational Modification
  • What is the Difference Between Gingelly Oil and Sesame Oil
  • What is the Difference Between Patent Ductus Arteriosus and Truncus Arteriosus
  • What is the Difference Between Lagophthalmos and Ptosis
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

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