Yes, abstract class can have constructor in Java. You can either
explicitly provide constructor
to abstract
class or if you don't, compiler will add default
constructor of no argument in abstract class. This is true for all classes
and its also applies on abstract class. For those who want to recall what is an
abstract class in Java, its a class which can not be instantiated with new() operator
or any other ways. In order to use abstract class in Java,You need to extend it and provide a concrete
class. Abstract class is commonly used to define base class for a type hierarchy
with default implementation, which is applicable to all child classes. By the
way difference
between interface and abstract class in Java is also one of the popular and
tricky
Java questions and should be prepared well for Java interviews.Can we declare constructor on abstract class
in Java is followup of other similar
Java interview questions e.g. Can
we override static method in Java?. Why interviewer ask this questions? Mainly because, trying to confuse programmer with fact
that since abstract class can not be instantiated, why abstract class need
constructor. In this Java Interview question article we will see that Abstract
class can have constructor in Java.