Contact Admin for Dumps and Queries

Just drop a mail to javasnips@gmail.com with subject as "SCJP Dumps" or "SCWCD/SCBCD Dumps".

What is the difference between Interface and Abstract class ?

Lets first analyze the definitions of Interface and Abstract class then we will proceed to the differences.

Interface
In general, from client point of view Interface is the set of services what he is getting.
And from service provider point of view, it is the set of services what he is offering.

A Java interface defines a set of methods but does not implement them. A class that implements the interface agrees to implement all of the methods defined in the interface, thereby agreeing to certain behavior.

Definition: An interface is a named collection of method definitions (without implementations). An interface can also include constant declarations.

Abstract Class

An abstract class is a type of class that is not allowed to be instantiated. The only reason it exists is to be extended. Abstract classes contain methods and variables common to all the subclasses, but the abstract class itself is of a type that will not be used directly. Even a single abstract method requires that a class be marked abstract

The Main Difference Between the Abstract Class And the Interface are:

1)When inheriting an Interface, we have to inherit all the methods of that Interface.. there's no other option. Where as with abstract classes we can inherit the members that we are in need of.

2) An Interface cannot have any declaration within it. Just the interface has to have body of the method and the method is to be used by the classes inheriting it. Whereas in case of Abstract Class it can have declarations (Other than the abstract method) and it can be further extended in the classes inheriting the Abstract Class.



Visitor Count

hit counter