Why abstract class are used in Java?

0 votes
181 views
Manish Kumar asked 23-Nov-2017 in programming by Manish Kumar
edited 25-Nov-2017 by Manish-Kumar

Why abstract class are used in Java?

1 Answer

0 votes
akriti kashyap answered 25-Nov-2017 by akriti kashyap

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!

UTKARSHASINGHROUL commented 9 days ago by UTKARSHASINGHROUL
Thanks for the answer.
       0