Well i got that there is always a default constructor with abstract class. OK. B

durgaram89

Distinguished
Mar 8, 2011
1
0
18,510
well i got that there is always a default constructor with abstract class. OK. But why not with interface? Thanks in advance.
 

Ijack

Distinguished
What would a constructor do for an interface? It only contains signatures for methods (and possibly constants and nested types), so there is nothing for a constructor to initialize. An abstract class can have attributes, which need to be initialized, hence needs a constructor even though it can never be instantiated.
 

kitkat12012

Distinguished
Nov 12, 2010
3
0
18,510
here's another way to look at it

1. constructors are called when objects are constructed
2. you don't wan to construct interfaces, you want objects to be derived from it
3. hence interfaces don't need constructors
 

Ijack

Distinguished
True, but that's also true for abstract classes. You never intantiate them, so you could argue that you don't need constructors. But when you subclass them, the constructor is used.

You don't really derive objects from an interface, it's more a description of methods that your class must provide.