what is the need of interface in java?

India
March 18, 2007 1:11pm CST
can any one tell what exactly the need of interface in java.what if we use classes for everywhere ?
1 person likes this
4 responses
@raghwagh (1527)
• India
19 Mar 07
There is no harm in using classes everywhere.But if you want to create a class deriving from more than one classes (multiple inheritance) then it is not possible in java directly.For for implementing such features we require interfaces.Also if you want to create just signature for the method and customise the function body then you can go for interface.Also we can totally avoid interfaces by using abstract class also whih has features like interface but then also you cannot extend more than one class at a time so no option but go for interfaces.Also interfaces come tu use when you go for RMI like implementations.
• India
19 Mar 07
Thank you very much. today i came to know one more feature of interface. They are very much essential for JDBC connections.These are used for creating the drivers.
@Mecboy (1050)
• United States
18 Mar 07
No java, can be an uploader or downloader, sometimes a java video player. Java is an applet that can be well, subtituting. When you don't like a flash video player. Java might take long it can a video player, powering up webcam and stuff. its a basic power station.
• India
21 Mar 07
Thank you.
• Italy
18 Mar 07
An interface in Java is a set of methods that indicates that a class implementing the interface has a certain behaviour, besides the one inherited from its superclasses. So interfaces are useful to obtain multiple inheritance.
@julie111 (44)
13 Apr 07
By using interface the caller does not need to know the underline implementation, and the underlined implementation can be determined at runtime ("Runtime Polymorphism") Example: -------- Accelerator is an interface to a driver. The accelerating mechanism varies from car to car, model to model. However the interface stays the same regardless of the car.