Article cover

18.11.2023

1

Beğenme

157

Görüntülenme

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

Yorumlar

Kullanıcı yorumlarını görüntüleyebilmek için kayıt olmalısınız!

Manoj Sharma

Konum

IN

© 2021 Patika Dev

facebook
twitter
instagram
youtube
linkedin

Disclaimer: The information /programs / events provided on https://patika.dev and https://risein.com are strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice and do not make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://patika.dev and https://risein.com disclaim any responsibility for financial decisions made by users based on information provided here.