The conversation between human and AI assistant.
When we can't create object of abstract class then why java allow defining a constructor in its body?
I have a question about Java. If we can't create an object of an abstract class, why does Java allow us to define a constructor in its body?
Good question! While you cannot create an object of an abstract class, you can still create objects of its subclasses. And these subclasses may have constructors that call the constructor of the abstract class. By defining a constructor in the abstract class, you can provide initialization logic that should be executed whenever a subclass object is created.