Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abstract vs Normal class inheritance performance

When you derive from a class and instance the subclass, the runtime also instances the super class, right?

Since abstract classes can't be instanced, are they not created by the runtime when a subclass is instanced?

If so, then abstract class inheritance would be faster than normal class instance?

like image 325
Joan Venge Avatar asked Nov 30 '22 12:11

Joan Venge


1 Answers

The runtime never creates separate instances of the base class and the derived class - it's just that the derived class instance also has all the variables etc of the base class, and runs the base class constructor as part of initialization. There's no difference here between "normal" base classes and abstract base classes.

like image 162
Jon Skeet Avatar answered Dec 04 '22 13:12

Jon Skeet