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

durgaram89

Distinguished
Mar 8, 2011
1
0
18,510
0
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
0
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.
 
Thread starter Similar threads Forum Replies Date
T Apps General Discussion 0
B Apps General Discussion 3
T Apps General Discussion 7
B Apps General Discussion 3
J Apps General Discussion 1
S Apps General Discussion 6
S Apps General Discussion 7
E Apps General Discussion 1
P Apps General Discussion 5
G Apps General Discussion 4
O Apps General Discussion 1
M Apps General Discussion 3
C Apps General Discussion 7
M Apps General Discussion 1
B Apps General Discussion 2
T Apps General Discussion 3
T Apps General Discussion 6
S Apps General Discussion 18
S Apps General Discussion 1
Z Apps General Discussion 1

ASK THE COMMUNITY