Abstraction Concept

Abstraction Concept

Data abstraction is the process of hiding certain details and showing only essential information to the user.

An abstract class may or may not have abstract methods but if there is an abstract method then all the child classes have to override it.

You can also do the partial implementation of Abstract Class methods

Abstract class A -> with 30 abstract methods, now you know all the child have to inherit 30 of them but you can also make it work like this:

  • class B (child of class A) -> implement 20 methods.
  • class C (child of class B or Grandchild of class A) -> implement 10 methods.
  • So, it completes the abstract methods.

The abstract class gives features to child classes. So, we restrict object creation because the class is too generic.

Assume we have an Animal class

class Animal { }

when we create an Animal object we can not guess which animal?

Animal animal = new Animal();

image

cc- does it make any sense?

So, to restrict this, we use abstract keyword.