Class | Interface |
---|---|
A class is a group of objects that has common properties. It is a template or blueprint from which objects are created. | An Interface is a blueprint of class. |
It can have final, non-final, static and non-static variables. | It can have only static and final variables. |
It can have non-abstract methods. | It can only have abstract methods. |
It can be instantiated. | It cannot be instantiated. |
It can contain constructors. | It does not contain any constructors. |
The members of a class can have access specifier like public, private or protected. | The members of an interface are always public as they have to be accessed by the classes implementing them. |
A class can inherit only one class and can implement many interfaces. | An interface cannot inherit any classes while it can extend many interfaces. |
The class keyword is used to declare a class. | The interface keyword is used to declare interface. |
Example: public class Test { public void draw(); } |
Example: public interface Drawable { void draw(); } |
No comments:
Post a Comment