0

why we cannot write constructor in interface? while we can write constructor in abstract class?

why we cannot write constructor in interface? while we can write constructor in abstract class?

21st Mar 2018, 1:49 PM
Prathamesh Dhuri
Prathamesh Dhuri - avatar
1 Resposta
0
Cause an interface can by definition not be constructed. However you can call the constructor of an abstract class from their child classes to construct the inherited parts of the super class. An abstract class can just not be instanced because it can include parts that are not declared, however the compiler still reserves memory space for it by calling it's constructor (if you have a variable with the type of an abstract class for example). An interface however is more or less just a pattern for the compiler to check if a class sticks to the rules set by it. It is not used during runtime however and cannot be used as a type.
28th Apr 2018, 8:59 AM
TransHedgehog
TransHedgehog - avatar