abstract class in Java is a class that cannot be instantiated on its own.
It is meant to be inherited by other classes to provide common behavior (methods,
variables) but force the subclasses to implement certain methods.
It can have both:
o Fully implemented methods (normal methods)
o Abstract methods (methods without body — no implementation)
a subclass must implement the abstract method:
If a class has at least one abstract method, it must be declared abstract
A class can be abstract even without abstract methods (for example, to prevent
instantiation).
Abstract methods must be implemented in the subclass unless the subclass is also
abstract
Cannot be private, static, or final
Top level class cannot be private
Abstract Methods in an Abstract Class
an inner class can be declared abstract in Java!
Can a subclass access static methods from the abstract class? Yes, via the class name,
not an object
If an abstract class has a static block, that block executes when the class is first
loaded.
Even though the abstract class cannot be instantiated, its static blocks still execute
if:
o You access any static method or static variable of the abstract class.
o Or when a concrete subclass is created (and it indirectly loads the abstract
class).
constructors in an abstract class are Package-private if you don't explicitly specify
an access modifier.