Abstract Class in Java

Abstraction:

  • Abstraction is the process of hiding the inner details and showing the functionality.
  • Abstraction can be achieved through abstract class or interface in Java.

Abstract class:

  • A class which is declared as abstract is called abstract class. An abstract class may or maynot contain abstract methods.
  • Abstract method is a method which has no implementation in it or a method without a body.

Example for Abstract method:

Example for Abstract class:

Output:

The addition of given numbers is:11
The subtraction of given numbers is:2
  • Abstract class cannot be instantiated. It should only be implemented and used by the subclass.
  • A subclass which inherits the abstract class either have to implement all the abstract methods present in the abstract class or declare itself as abstract.

Share this website !!!
Facebook Twitter Linkedin