CrazyEngineers
  • What is Need of Abstract Class In java ?

    Updated: Oct 26, 2024
    Views: 1.6K
    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.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • manishsvkumarsingh

    MemberJul 25, 2015

    GOOD CONCEPT #-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register