Friday, November 18, 2011

Difference between interface and class

First, an interface can only contain abstract methods and/or static final variables (constants). Classes, on the other hand, can implement methods and contain variables that are not constants.

Second, an interface cannot implement any methods. A class that implements an interface must implement all methods defined in that interface.

An interface has the ability to extend from other interfaces, and (unlike classes) can extend from multiple interfaces.

Furthermore, an interface cannot be instantiated with the new operator; for example, Runnable a=new Runnable(); is not allowed

No comments:

Post a Comment