When to use Interface?

 Posted by Nighil on 5/16/2013 | Category: OOPS Interview questions | Views: 3335 | Points: 40
Answer:

Interface General Explanation

we can implement multiple inheritance with help of Interface and it will contain signature of methods or events no implementation will be there.

When to Use it

if we want to Implement same signature in different class then we can use it.
consider a company where there are staffs and supporting staffs. All will be given salary but staff salary calculation is different from supporting staff salary calculation.

here is how it is implemented

public interface ISalary
{
decimal CalculateSalary();
}

public class Staff : ISalary
{
public decimal CalculateSalary()
{
//Staff salary calcuation logic
}
}
public class SupportingStaffs :ISalary
{
public decimal CalculateSalary()
{
//Supporting Staff salary calcuation logic

}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response

More Interview Questions by Nighil