# What is abstract Keyword?

&#x20;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).&#x20;

Following are different contexts where abstract can be used in Java.&#x20;

1\. Abstract classes&#x20;

2\. Abstract methods

&#x20;**Abstract classes**

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

In java programming we have two types of classes they are&#x20;

1\. Concrete class&#x20;

2\. Abstract class

#### &#x20;Concrete class

&#x20;A concrete class is one which is containing fully defined methods or implemented method.

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfdjZfBY3_kATJvnCJ%2F-LTfeU9nxziOoL_WrCIr%2Fimage.png?alt=media\&token=870f4377-13fa-4ce2-b22e-21794a9b2208)

#### &#x20;Abstract class

&#x20;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.

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfdjZfBY3_kATJvnCJ%2F-LTfecCxNFvKKXzuv2_h%2Fimage.png?alt=media\&token=7bbe9fe6-63dc-4e3c-b860-8391a1ea30b9)

#### &#x20;Abstract method

&#x20;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.

&#x20;If any class has any abstract method then that class becomes an abstract class.

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfdjZfBY3_kATJvnCJ%2F-LTfeu5iayRarOBZNLif%2Fimage.png?alt=media\&token=d9d8228c-3d34-46c2-a5ea-04929d714477)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfdjZfBY3_kATJvnCJ%2F-LTff3dXhoCHk0Q5xGIQ%2Fimage.png?alt=media\&token=69edd771-f44d-4bcc-9a88-36d62e2a9e95)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfdjZfBY3_kATJvnCJ%2F-LTff8WK6A68ywN-XaZr%2Fimage.png?alt=media\&token=53c11cdc-8822-46fc-9650-75fdb4bb4b83)

#### &#x20;Why can’t we create the object of an abstract class?

&#x20;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.&#x20;

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.
