Saturday 15 October 2011

what is an interface in java?



An interface is a class containing a group of constants and method declarations that do not provide implementation. Interface contains all abstract methods. Interface allows what a class must but do not specify how to do.

One class can implement any number of interfaces. We must use implements keyword instead of extends. This is the way of multiple inheritance, which java supports.

An interface can have instance variables also that can be used by its subclasses. All the instance variables must be declared as public, final and static. If public, static and final are omitted, they are assumed by default.

The public interface of a class is a contract between the client code and and the class that provides the service. Concrete classes implement each method. Java interface declares only the contract and no implementation. 

Interface should only contains abstract methods.

The access specifier must be  public.

The variables are public, static and final.

Multiple inheritance is possible.

Inheritance uses key word implements.

Interfaces must be public.






No comments:

Post a Comment