Question:
What is difference between an Abstract class and Interface?
Answer:
1.Interfaces provide a form of multiple inheritance. A class can extend only one other class. 2.Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc. 3. A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. 4. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. Source: CoolInterview.com
An Interface has only Abstract methods and final static variable, where as an Abstract class have both instances methods as well as abstract methods. Source: CoolInterview.com
Answered by: Arjun | Date: 3/20/2010
| Contact Arjun
Abstract are the classes in which both abstract methods and concrete methods(the methods which have implementation) can be written whereas in interface only abstract methods which dont have implementation are there.Other difference is an abstract class can extend only one class but an interface can implement many classes which supports multiple inheritance. Source: CoolInterview.com
Answered by: Swathi | Date: 4/6/2010
| Contact Swathi
Interfaces provide a common method's signatures with no body(implementations) ,so that the sub class which implements the interfaces is responsible for providing the method implementation. the method implementation is independent of other class's method implementations.
Interfaces can't be instantiated directly but the reference of this interface can be assigned to the object of its subclass. Source: CoolInterview.com
Answered by: Ravi.B | Date: 4/23/2010
| Contact Ravi.B
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|