What is the purpose of interface? And tell the difference between the class and interface?

Showing Answers 1 - 12 of 12 Answers

siddaraju

  • Oct 9th, 2005
 

interface:suppose something changes often and often so it is not possible to define anything on that situation we go for interface.the implementation is left to subclasses.Ex:in JDBC we made Connection as interface (bcz user can use different type of driver based on his requirement)

  Was this answer useful?  Yes

siva

  • Oct 14th, 2005
 

The interface supports multiple Inheritance .with one reference we can call all methds of interface witch was implemented in all classes.

  Was this answer useful?  Yes

kailash

  • Oct 18th, 2005
 

 interface ( set of functions with out body )

  in case of interface there is interface inheritance not multiple inheritance

 when you want to create a component you have to provide the interface for client . the interface is implemented on the component and is known to the client (only name of the function to the client)

interface is basically for the communication.

  Was this answer useful?  Yes

anshuman chhotaray

  • Oct 25th, 2005
 

Java dose not support multiple inheritance.To provide this functionality interface is there in java.Interface are design to support dynamic method resolution at run time.The main difference between class and interface is we can create object of a class but can not create object of an interface.

amit

  • Jan 11th, 2006
 

Interface is like defining some protocol.

When you start building some module or package you must code it into some proper manner so if someone else wants to update or work on it, its working is clear for them. Means it should be generic code. So instead of starting whole thing into single class, you thing about some generic methods, constants your module needed, without thinking of its implementation. So here comes the concept of Interface and Abstract Classes.

                When you start implementing method define in Interface you start working with classes which implementing your interface.

 

                   

Amit Patil

  • Sep 19th, 2007
 

Interface is a contract which a implementing class has to satisfy, Interface isnt a patch for not having multiple inheritance and wasnt built meant to support multiple inheritance. It was so they would have provided multiple inheritance. In-fact it exists in C++ (They there is no keyword interface...it can be implemented using pure virtual functions). Interface is to expose only the functions of the class hiding the implementation from the user. Good designing techniques state that a class has to be referenced by its interface not its concret implementation.
Abstract class can have some implementation and they may also have abstract functions. Abstract functions ensure that the subclasses implement abstract functions.
As stated above please read Khalid Mughal for more details

rajekra

  • Jun 6th, 2009
 

If you want pluggable architecture for your design, you should go with interface option.

Say example, I have java based car racing video game it would support BMW, AUDI. So I provide interface with leftKey(),rightKey(),upKey(),downKey() methods which would support for car moving.

One third party(e.x. MERCEDEZ) wants to provide his car for this racing, so he have to implement same methods in the interface to car moving in our game.

User when press leftKey(), then our video game code execute leftKey() method on particular car, then it's start moving and have fun.

The above same scenario was followed in JDBC Connection interface mechanism.


Regards,
Rajasekaran,WIPRO

  Was this answer useful?  Yes

An interface is a specification of method prototypes. All the methods of interface are public and abstract. They are public because they should be available to third party vendors and they are abstract because their implementation is left for third party vendors.

A class is model for creating the objects and it contains description of properties or variables and actions or methods of its objects.
We cannot create objects for interfaces.


  Was this answer useful?  Yes

sachin

  • Aug 1st, 2011
 

interface is mainly used to achieve standardization and loose coupling.. Its like a media between two systems.

Interface can be treated like rules, where only method definition is present but not implementation., i.e, all methods in an interface are abstract and the implementation must be present in the other systems(i.e., which implements the interface)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions