Interface and Abstract Class - Coddicted

Interface and Abstract Class

An Interface declaration introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement it by providing implementations for its abstract methods.
An Abstract Class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An Abstract may contain concrete methods also. It can only be used as a super-class for other classes that extend the abstract class. Abstract class is the concept and implementation gets completed when it is being realized by a subclass. 
 
 S.No.
 Interface
 Abstract Class
 1.
 Java Interfaces are implicitly abstract and cannot have implementations
 An Abstract class can have instance methods that implement a default behaviour
 2.
 Java Interface supports multiple inheritence hence a class can implement multiple interfaces
 It does not support multiple inheritence hence a class can extend only one abstract class.
 3.
 An Interface can extend one or more interfaces
 An Abstract class can extend another java class and implement multiple interfaces
 4.
 Variables declared in an interface are default public and final .
 Variables declared in an abstract class can be public,protected ,private or default.
 5.**
 Interfaces are slower as compared to Abstract classes
 Abstract classes are faster than interfaces.

** why?


Back To Top
Rate this post

Leave a Reply