Sunday, June 26, 2011

.Net Interview Questions - OOP

What is Object Oriented Programming (OOP)?
Object-oriented programming (OOP) is a programming language model organized around objects. At this poing you may have a question in your mind, what is an object? its simple, an object can be anything which has some attributes and hehaviour. For example, hope now you are infront of a computer monitor, the monitor itself is an object, it has a lot of attributes like Make, Size, Type etc...

In OOP we use classes and objects to represent our data and logic. For example consider the following C# example.

public class Monitor
{
public string Make
{
set;
get;
}

public int Height
{
set;
get;
}

//etc......

}
The above class defines a structure of the computer monitor. An object of this class can represent a computer monitor.
OOP Concepts


  1. Data Abstraction : The act of representing essential features without showing the back ground details.

  2. Data Encapsulation: The wrapping up of data together into a single unit.

  3. Inheritance: The act of inheriting properties of an object into another.

  4. Polymorphism: The ability of a data to behave in multiple forms.

Possible questions about OOP concepts from a .NET stand point are:



  1. What is Data Abstraction? ans: see above definition

  2. What is Encapsulation? ans: see above definition

  3. What is inheritance? ans: see above definition

  4. What is Polymorphism? ans: see above definition

  5. Does .Net support multiple inheritance? ans: no

  6. Example for polymorphism? ans:function overloading, overriding and operator overloading

  7. Real world example for data abstraction? ans: when we press the start switch of a car or bike will get started, we might not need to know the internal process. we gave an input and we got an outcome.

  8. What is a class and an object? ans: class is a blueprint for creating objects. An object is an instance of a class and it have the properties and behaviours defined in the class.

No comments: