Sunday, 6 October 2013

Abstract class(Abstract class) and interface are opposite side of same coin. You can declare interface by interface interface_name.

Following are the some important points about interface:
  •  Interface contain only method signarute.
  • As like abstract class,interface can not be instantiated.
  • In interface by default member variables are public static final.
  • Interface does not have constructor.
  • One interface can extend multiple interfaces at once. As this is not applicable for classes.
  • To implement a interface we use "implements" keyword.
  • Java contain some empty interfaces like Serialzable, Cloanable...etx. They don't have any method signature.
 Now we will see the difference between abstract class and interface :



  •  Interface contains only method signature however abstract class may have method body.
  • Member variable inside interface are by default public static final where as you can declare different type of variable in abstract class .
  • Multiple interfaces can be implemented at once where as multiple inheritance is not allowed in abstract classes.

No comments:

Post a Comment