Hello Friends,
Doubt in Interface:
1. How do we use Interface in real time scenario.
2. How to assign Interface for a given Class?
3. How to inherit two Interface in a class?
4. Why do we use interface instead of creating object for a class and using in another class?
Thanks In Advance :)

Abhishek KumarPosted Mar 4, 2014, 7:51 AM
1. How do we use Interface in real time scenario.
Interface is used basically where we don't want our client to know about the changes proposed. Interface creates a layer where you can add new functionality without doing much code change in client.
2.How to assign Interface for a given Class?
below is the interface which is returning the brand name and accepting car id as a parameter.
Interface Icar
{
string GetCarDetail(int Carid)
}
Interface IBike
{
string GetBikeDetail(int Carid)
}
Implementation
public class car :Icar
{
}
3. How to inherit two Interface in a class?
Public Class Vehicle :Icar,IBike
{
}
4. Why do we use interface instead of creating object for a class and using in another class?
Abstraction can be achieved by doing this.
Thanks
Munesh SharmaPosted Mar 4, 2014, 3:35 AM
Firstly i will tell you why we use interface.
(1):- Interface allows us to develop loosely coupled system.
(2) :- Interface are very useful for dependency Injection.
(3) :- Interface makes unit testing & mocking easier.
interface can't have implementation for any of its method.There is no access modifiers.
declaring Interface
Public interface interfacename
// interface members
int id;
char Id;
How to inherit two Interface in a class
saurabh mittalPosted Mar 4, 2014, 3:06 AM
1. we can useinterface like this:-
interface IOurDevices { void connectToDevice(); }
2.to assign interface to class just inherit interface class and define the method:-
class USBDevice : IOurDevices
{
void connectToDevice() { connectionState = "connected"; }}
3.class USBDevice : IOurDevices,GenericDevice
{
//define ur methods
}
4.for security reasons we use interface beacause we can't create an object of
interface so there is no communication at runtime.
Jaganathan BantheswaranPosted Mar 4, 2014, 2:53 AM
1. How do we use Interface in real time scenario.
2. How to assign Interface for a given Class?
Answer for both the question is Here, the real time usage of interface in Log4Net.
3. How to inherit two Interface in a class?
You can do like, public class C : A, B // A & B are interfaces here
4. Why do we use interface instead of creating object for a class and using in another class?
As mentioned in the answer 1 & 2, interface is just a contract which should be implemented in the Class which is to be initiated.