Article cover

18.11.2023

1

Like

60

Views

What is Abstract Class in java and how to create abstract class in java

An abstract class in Java is one that is intended to be subclassed by other classes and cannot be instantiated on its own. It can have concrete methods, abstract methods, or a mix of both; it acts as a model for other classes.

Abstract Keyword:

The abstract keyword is used to declare an abstract class. Abstract classes may have abstract methods (methods without a body) as well as concrete methods (methods with a body).

Abstract Methods:

Abstract classes can have abstract methods, which are declared without a body and are meant to be implemented by the subclasses.

what is abstract class in  java

Subclassing:

When you extend an abstract class, you must either provide concrete implementations for all the abstract methods in the subclass or declare the subclass as abstract.

what is abstract class in  java

 

 Constructor:

Abstract classes can have constructors, and they are invoked when a subclass object is created. However, abstract classes cannot be instantiated directly.

what is abstract class in  java

Usage:

Abstract classes are useful when you want to provide a common interface or functionality that should be shared among multiple related classes.

what is abstract class in  java

In this example, Shape is an abstract class with an abstract method draw() and a concrete method display(). The Circle class extends Shape and provides a concrete implementation of the draw() method. The display() method is inherited from the Shape class.

Java101
Object Oriented Programming
Frontend Web Development Projeleri

Comments

You need to log in to be able to comment!

Manoj Sharma

Location

IN

© 2021 Patika Dev

facebook
twitter
instagram
youtube
linkedin