Friday, March 27, 2009

OOPs Interview Questions Part IV

Question: What is an interface? How to implement an interface? 
Answer: An Interface is a collection of semantically related abstract members. An interface expresses through the members it defines, the behaviors that a class needs to support. An interface is defined using the keyword interface. The members defined in an interface contain only definition, no implementation. The members of an interface are all public by default, any other access specifier cannot be used. 

An interface is implemented using implements keyword. A class may implement more than one keyword. 

When a class inherits and implements at the same time, the inherited parent class name is written first, followed by the names of the interfaces to be implemented. 

Question: Is multiple inheritance possible in .NET? 
Answer: No. Multiple inheritance is not possible in .NET. This means it is not possible for one class to inherit from multiple classes. However, a class may implement multiple interfaces. We may also declare objects of different classes in a class. This way, the encapsulated class may be instantiated in other classes. 

No comments: