Wednesday, September 29, 2010

What is Interface, DIFFERENCE BETWEEN CLASS AND INTERFACE

INTERFACE
1.    Interface is a group of constant and method declaration. An interface may be created fro different classes
2.    Through interface polymorphism is supported by java.
DIFFERENCE BETWEEN INTERFACE AND ABSTRACT CLASS.
1.    interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
2.    Variables declared in a Java interface is by default final. A Java abstract class may contain non-final variables.
3.    Memebers of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc. or abstract class may contain non-public members.
4.    Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
5.    A Java class can implement multiple interfaces but it can extend only one abstract class.
6.    interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.

DIFFERENCE BETWEEN CLASS AND INTERFACE

1.    Interface is little bit like a class... but interface is lack in instance variables....that's u can't create object for it.....
2. Interfaces r developed to support multiple inheritance...

3. The methods present in interfaces r pure abstract.

4. The access specifiers public,private,protected r possible with classes.but the interface uses only one spcifier public.