Why does an abstract class can have a constructor | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does an abstract class can have a constructor

As we know that, we can't create the object for an abstract class and also we know that a constructor initialized the value of class automatically

14th Aug 2019, 4:43 AM
Shivam chanchal
Shivam chanchal - avatar
3 Answers
+ 5
Not everything in an abstract class is totally abstract.
14th Aug 2019, 7:33 AM
Sonic
Sonic - avatar
+ 2
Abstract class provide us with features and let us specialise aspects it by inheritance. Those features of an abstract class might require some data, of course. It there wasn't a constructor then user of an abstract class would be obligated to define that data in constructor of a derived class. It's not convenient at all :) So we use constructor of a base class for that reason.
14th Aug 2019, 5:35 AM
Ilya Vouk
Ilya Vouk - avatar
0
Totally abstract class is called an interface.
14th Aug 2019, 7:59 AM
Ilya Vouk
Ilya Vouk - avatar