An abstract class need not include any abstract methods.
Is there any other reason to make a class abstract other than the fact that abstract classes can't be instantiated?
An abstract class need not include any abstract methods.
Is there any other reason to make a class abstract other than the fact that abstract classes can't be instantiated?
I have extracted below points from Why should I declare a class as an abstract class?
Abstract classes improve the situation by preventing a developer from instantiating the base class, because a developer has marked it as having missing functionality.
It also provides compile-time safety so that you can ensure that any classes that extend your abstract class provide the bare minimum functionality to work, and you don't need to worry about putting stub methods that inheritors somehow have to magically know that they have to override a method in order to make it work.
There cannot be an abstract function in an non abstract class!
So if you need an abstract function in your class for whatever reason you must declare your class to be abstract.
Why would I need an abstract function?
What is the point of using abstract methods?
As for your question a scenario I can think of is as follows -
You can make a class as abstract ,even if you don't want to implement all of the interface methods that the class implements. According to java docs.
Any way you can't instantiate a class that declared with abstract.
The principal role of an abstract class is to provide an appropriate root class from which concrete, (i.e. non-abstract) subclasses can be derived. This is a powerful and versatile feature which promotes code re-use. Abstract classes encapsulate general features that are common to a range of data types - features which are too general to be meaningful in the abstract class, but which can be overridden in a subclass
Any class with an abstract method is automatically abstract itself and must define itself as such with the keyword abstract - interestingly, an abstract class need not contain any abstract methods
An abstract class cannot be instantiated - in other words you cannot create instances (objects) of an abstract class
References to objects of an abstract class can be declared even though objects of abstract classes cannot be instantiated, e.g Account a ; will not generate a syntax error
If a subclass of an abstract class overrides, i.e. provides an implementation of every abstract method in its superclass, the subclass is called a concrete class and objects of the subclass can be created
If a subclass of an abstract class does not override (implement) all of the abstract methods it inherits, that subclass itself is also abstract and must be declared as such
Abstract class means the definition of the class is not complete and hence cannot be instantiated. Even though it does not have abstract method, it is an indicator that the class is available for inheritance. Even though it has implementation for all the methods in it, the implementation may still not be complete and must be overridden by the extending class.
Probably not. It would prevent a "static helper" class from being instantiated, but I think using it that way would be poor style.
As others say, if it's intended to be a base class -- with descendants declaring & implementing interfaces/ functionality, which is too specific for the superclass -- then
abstract
could be appropriate in the superclass.In that case it's a declaration that the super is not useful on it's own, and that subclasses will do something more -- which they will specifically declare.