Abstract class in Java programing language

Abstract class in Java programing language

In this tutorial, we will discuss the OOP concept of abstract class in Java programing language.

Abstraction is one of the Oop concepts.  A class that contains at least one abstract method is known as an abstract class.

The abstract class is a class which contains at least one abstract method. That means the abstract method does not do any implementation, it just has a signature.

So abstract methods are methods that can be only declared, not defined.

The class becomes abstract if one or more of the methods are abstract.

We cannot create an object of an abstract class.

Sub class must provide an implementation for the abstract methods of the super class or themselves be declared as abstract.

What is the use of an abstract class?

Abstraction is a concept that hides implementation details and only presents the features to users.

Syntax of abstract class

abstract class A{
// abstract is a keyword
// abstract class have abstract and non-abstract methods
// implementation of abstract methods is out of the another class
// all abstract methods in abstract class must implement another class }


Syntex of the abstract method

abstract void method_name();

//no body and abstract
//only declare no define

Program 1

In the following example, Abstract1 is an abstract class and it has two methods inside the class

abstract void run() – it is an abstract method, it has no implementation

void print() – It is a normal method with implementation within the class

implementation of abstract method(void run()) is provided by the override class

Example
Understanding the real example of abstract class
In this example, an Animal is an abstract class. that contain only one abstract method myanimal() Its implementation is provided by the dog and cat classes.
Example

An abstract class can have properties as an abstract method, method, constructor, and even main() method

Example

Related Links

Encapsulation in C++                                       Encapsulation in Java

Polymorphism in C++                                      Methodoverriding in Java

Method overloading in java                             Constructor overloading in Java

Exception Handling in Java

 

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.