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
An abstract class can have properties as an abstract method, method, constructor, and even main() method
Related Links
Encapsulation in C++ Encapsulation in Java
Polymorphism in C++ Methodoverriding in Java
Method overloading in java Constructor overloading in Java
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.