Difference Abstract Class and Interface

Difference between Abstract Class and Interface 

Guys, Difference between Abstract Class and Interface is one of the confusing topic for beginners in object oriented programming language. The difference between the two concepts are spotted simple in this page. You can have a look and make it clear.

The main difference between Abstract Class and Interface is, Interface do not have any implementations.
They contain only the method name. I.e. the signature part. The body implementation part is done in the class in which it is implemented. This is the reasons why methods of an interface are called as implicitly abstract.  A class which is implementing an interface has to implement all the methods of the interface.
Interface is not a class. Interface is an entity.
Interface forms the contract between the class and the outside world.
Interface should be implemented in another class using the keyword implements.
Interface cannot be instantiated, but we can instantiate a class that implements the interface.
Java does not support multiple inheritances.So the concept of multiple inheritances can be achieved by using interface in java.
Also many interface can be implemented in a class using the keyword implements with the interface names separated with commas.

An abstract class may contain complete methods or incomplete methods.
An abstract method declared in abstract class should be sure used in the class in which it is extended. A method with abstract keyword should be implemented in the class in which it is extended. All the abstract methods should be implemented in the class in which it is extended. A method without abstract keyword in abstract class should be implemented right there itself.
A class may inherit only one abstract class.
An abstract class can contain fields, constructors, etc…
Abstract classes should be extended with another class or abstract class using the keyword extends.
Abstract classes are faster than interface.

No comments:

Post a Comment

My Profile