What is the difference between an interface and abstract class?

In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

Showing Answers 1 - 16 of 16 Answers

Anilkumar

  • Dec 1st, 2005
 

Abstract class means

1)We can have concreate methods and abstrat methods

2) We can give implementation for concreate methods.

Interfaces means

1)we could not have concreate methods.All the methods are abstract methods implicitly.

2)And those methods allows only public access specifier only.It wont

allow any final,static keywords with methods .

  Was this answer useful?  Yes

Sangita_agg

  • Jul 28th, 2008
 

Abstract classes act as the buliding block whose object cannot be created. We include common functionality in abstract class which can inherited by the sub classes. They are not 100% abstract whereas interface provide 100% abstraction in this no function definition is there only we specify the common behaviour with no definiton..

  Was this answer useful?  Yes

Riki

  • Aug 30th, 2015
 

Abstract classes defines what something is. It is a definition of what a class (base class) is. Like a washing machine washes cloth, so in an abstract class will contain a abstract method to wash cloth. Now whoever class wants to become a washing machine :D can derive from that abstract class yet there implementation can be different ()
Interface defines what something can do (not what something is). It acts as an contract to validate an implementation. Say, a person can walk, talk as he IS A human (because we humans are derived from some God made abstract class). Now he learns a skill and goes for a job interview but what is validation that the person has that specific skill is the certificate. Dah!. So the certificate is acting as an interface or a contract and if someone is implementing that contract (it means the person has that specific skill) will get the job.

  Was this answer useful?  Yes

Gaurav

  • Aug 17th, 2016
 

Interface is like a definition on some thing but not example where-else abstract define the example. Like : Addition of two integer define in Interface and 5+2 = 7 in an abstract.

  Was this answer useful?  Yes

Ramprit Sahani

  • Sep 1st, 2016
 

Interface is an abstract class which has only public abstract methods and the methods only have the declaration and not the definition. These abstract methods must be implemented in the inherited classes.
In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods

  Was this answer useful?  Yes

Naveen Kumar Shivanadri

  • Sep 8th, 2016
 

The basic difference is

Abstract class can contain abstract methods (a method without method body) as well as concrete methods (a method with method body). Where as in the interface there is only for abstract methods there is chance for abstract methods only but not concrete methods.

By using abstract class we can do only single line inheritance but using interface we can implement multiple inheritance.

Naveen Kumar Shivanadri

  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