What is Need of Abstract Class In java ?

WARDHAMAN BEDMUTHA

WARDHAMAN BEDMUTHA

@wardhaman-HBFrS6 Oct 26, 2024
Abstract class is a class in java which can not be instantiated. In simple terms you can not create object of that class.

Why do we need of Abstract Class then ?

Lets consider we have one parent Class Board and subclass like WhiteBoard and BlackBoard.


[​IMG] upload_2015-7-24_10-30-2

Board B =new WhiteBoard() ----- This is valid

WhiteBoard=new WhiteBoard() ---- This is valid

BlackBoard =new BlackBoard() -- This is valid

Board B =new Board() -- what type of object will be Board?What will be its color, length and width?

Will it make any sense to create object of type Board ?

Simply No.We will unable to know type of object created from Board.So in order to avoid creation of Object of Board we can mark this class as Abstract.

Abstract classes are the classes which can not be instantiated.

In above example,

Board should be declared as Abstract while designing.

WhiteBoard and BalckBoard are the concrete classes.

Concrete classes are the classes which can be instantiated.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform