What is the diffrence between an Abstract class and Interface

Showing Answers 1 - 6 of 6 Answers

Dipty

  • Apr 3rd, 2005
 

We can extend a abstract class while as we need to implement an interface. We can implement multiple interfaces but can extend from only one abstract class.

  Was this answer useful?  Yes

Prakash

  • Apr 7th, 2005
 

1.Using Interfaces,the concept of multiple inheritance can be used.But with abstract classes,this cannot be done. 
2.Abstract classes may have implementation of one or more methods,but interfaces have only the method signatures.

  Was this answer useful?  Yes

madhuri

  • Apr 30th, 2005
 

Interfaces contains prototype but not the behaviour ie all interface methods are by default abstract.Abstact class contains abstract methods and can also have functional methods

  Was this answer useful?  Yes

iris

  • May 3rd, 2005
 

Differences 
 
1. The difference between interface and abstract class is that in an interface no method body is permitted only method declarations.In an abstract class you can have method bodies as well as declarations.You can assume interface as absolute abstract class. 
 
2.As interface contains only method declarations they are assumed abstract by default, you dont have to explicitly declare them as abstract.But as the abstract class can contain method bodies as well as method declarations , you have to explicitly state them as abstract methods. 
 
3.The modifiers for methods in interface can be only public, the modifiers for methods in abstract class can be public or protected. 
 
4.One or more interfaces can be implemented, only one abstract class can be extended 
------------------------------------------------ 
Similarities 
 
1.Both the interface and the abstract class can contain zero or nil abstract methods. 
 
2.In both cases all the abstract methods declared should be implemented/extended respectively. 
 
----------------------------------------------------------- 
Note: Since an abstract class cannot be instantiated and it can contain method body..you can use it to your advantage if and when required

  Was this answer useful?  Yes

Vijay Chaudhary

  • Jul 31st, 2005
 

Variables declared in Interface are static and final by default. 

  Was this answer useful?  Yes

As far as difference is concerned, then the only difference between interface and Abstract class is:
 In the interface we can only declare a method, we can not define it within interface
But in the abstract class we can declare as well as we can define also.

Its use differ in case of multiple inheritance.
If we need to implement the multiple inheritance, in that case we use Interface, other wise we are free to use Abstract class. Its  all depend upon the scenario, what it needs.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions