Why abstract class are used in Java?

Asked 23-Nov-2017
Updated 25-Nov-2017
Viewed 629 times

1 Answer


1

Abstract Class!

Why  abstract class are used in Java?

Declaring abstract to a class, may or may not hold abstract methods are called abstract class. They can only be sub-classed but not instantiated. Static methods and fields may be the part of an abstract class. When they are sub-classed, these sub-classes start implementing abstract methods in their parent class. In case if it does not it can be declared under abstract class.

Declaration of the abstract method is completed without an implementation. For example:
abstract void add(int x , int y);
Why  abstract class are used in Java?
Abstract classes can be used, under following affirmation:

  • Sharing the code among the closely related classes
  • Declaring non-static fields. This would allow modifying and access to the object states to which they are known
  • Classes which have been extended from abstract class should have access modifiers except for public those who had been loaded with multiple methods or fields
Well, it was brief about why are abstract classes used in java...

Hope, you enjoyed reading!

Cheers!


Comment
Thanks for the answer. - Anonymous User15-May-2019