Hi Stephen, A frequent doubt this one... See if these reasons satisfy u..I couldnt think of any more for the time being.... for one thing...Interfaces are not allowed constructors but abstract classes are.Abstract classes can be given constructors which of course cannot be called directly since the class is abstract.When u instantiate the class that extends this abstract class,u can place an explicit call to super or the system calls it automatically in the hierarchy. And another... abstract classes can have non-abstract methods also but an interface's all methods are implicitly abstract.
All variables of an interface all implicitly static final ,not so for an abstract class. so simply put an Interface could be called a pure abstract class.
i also have such kind of questions... we have the "pure" abstract class--interface,then what's the reason for the abstract class being exist? more... why Java uses the single inheritance rather than the multi-inheritance mechanism which is used in C++ ? any advantages? thinking....
Originally posted by simeon shi: i also have such kind of questions... we have the "pure" abstract class--interface,then what's the reason for the abstract class being exist? more... why Java uses the single inheritance rather than the multi-inheritance mechanism which is used in C++ ? any advantages? thinking....
Classes are to support inheritence, Interfaces are implemented, Abstract classes can be extended and there abstract methods can be implemented. Multi inheritance has Diamond shape problem regarding instance variables so if you do not declare instance variable as virtual you will end up having duplicate copies of member varible(I do not remember whether compiler forces it or not, actually compiler should force it.) If a class has been defined and it does not have virtual member variable then you can not enjoy multi inheritance. HTH CMIW
------------------ Regards Ravish [This message has been edited by ravish kumar (edited December 12, 2001).]
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh