What is abstract Keyword?

abstract is a non-access modifier in java applicable for classes and methods but not for variables. It is used to achieve abstraction which is one of the pillars of Object Oriented Programming (OOP).

Following are different contexts where abstract can be used in Java.

1. Abstract classes

2. Abstract methods

Abstract classes

We know that every java program must start with a concept of class that is without classes concept there is no java program perfect.

In java programming we have two types of classes they are

1. Concrete class

2. Abstract class

Concrete class

A concrete class is one which is containing fully defined methods or implemented method.

Abstract class

A class that is declared with abstract keyword is known as abstract class. OR, the class which is having partial implementation (i.e. not all methods present in the class have method definition). In short, an abstract class is one which is containing some defined method and some undefined method.

Abstract method

An abstract method is one which contains only declaration or prototype but it never contains body or definition. In order to make any undefined method as abstract whose declaration is must be predefined by abstract keyword.

If any class has any abstract method then that class becomes an abstract class.

Why can’t we create the object of an abstract class?

Because these classes are incomplete, they have abstract methods that have no body so if java allows you to create object of this class then if someone calls the abstract method using that object then what would happen? There would be no actual implementation of the method to invoke.

www.testingbar.com ||Sujoy@testingbar.com Also because an object is concrete. An abstract class is like a template, so you have to extend it and build on it before you can use it.

Last updated