What is Interface? Explain with an example.

Answer Posted / dharmendra kumar

Interface is a syntactical contract that all the derived
classes should follow.

public interface MotorStateObject
{
int State{ get;}

void Running();

void Stop();

int Speed { set;get; }

}
public class Car : MotorStateObject
{ .....
}

public class Bike : MotorStateObject
{......
}

public class Bus : MotorStateObject
{......
}

public class MotorState()
{
public void applybrake(MotorStateObject Object)

{
MotorStateObject.Stop();
}
}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to insert the data from the grid view to database table though button click.pls send the answer to mail id suri1319@gmail.com

1496


How do I simulate optional parameters to com calls?

509


Is constructor a static method?

497


What is datetime parse in c#?

519


what is object-oriented programming (oop) language?

487






What exactly happens when we debug and build the program?

2177


What is virtual in c#?

483


How is a strongly-named assembly different from one that isn’t strongly-named?

611


What Is An Interface Class?

564


Explain the access modifiers in c#?

493


Explain the types of comments in c#?

552


How do you escape in c#?

508


Is a c# interface the same as a c++ abstract class?

567


What does void mean in c#?

522


Can you have parameters for static constructors?

541