SCJP Certification

Sun Certified Java Programmer Certification exam essentials

August 25th, 2009

Difference between abstract classes and interfaces

Java Facts, by Daisy Williams.

Abstract class: In java, an abstract class is a class that is partially implemented. It provides design convenience. An abstract class is made up of one or more abstract methods that are declared but left unimplemented.

Interface: An interface is a reference type that defines a contract. An interface body consists of method declarations and constants. All methods and constants in an interface are public. Interfaces are left completely unimplemented, i.e., no method in the interface is implemented. All methods of an interface are abstract and the method body is absent.

The following table depicts the difference between abstract class and interfaces:

Abstract class Interface
It is declared with the keyword abstract. It is declared with the keyword interface.
It can contain non-abstract methods. By default all the methods of an interface are abstract.
An abstract class can contain private methods. An interface cannot contain private methods.
It can contain instance variables and final varibales. It contains final varibales only.
Share

Back Top

Responses to “Difference between abstract classes and interfaces”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*