Friday, June 8, 2012

What are the basic concepts(Features) of OOPs??

These are the basic concepts(Features) of OOPS.
1.Inheritance.
2.Polymorphism
3.Encapsulation.
4.Data Abstraction.
5.Reusabilty

In addition to these 5 we have Class,Objects,Message passing and delegation. these 5 are importent concepts

Inheritance: It is an approach which allows accessing members defined in a class from another class by establishing parent child relation ship.

Ex: In .Net Object class is parent class for all the classes.


Polymorphism: "entities behaves differently depending on the input they receive" is known as polymorphism.

Overloading and overriding com under polymorphism

Method Overloading: Defining same method name with the different signatures are known as overloading.
The changes in signature can be any of following.

1.Change in number of methd being passed to a method.
2.Change type of parameters being passed to the method.
3.Chane order of parameters being passed to a method.

Public void YourMethodName()
Public void YourMethodName(int x)
Public void YourMethodName(int x, string y)
Public void YourMethodName( string y,int x)

 Simply it is an approach which allows you to provide multiple behaviors to a method.


Method Overriding : A method defined in parent class is redefine under its child class with same signature and same parameters is known a s method overriding.

Public virtual void Display(int x)  -- Parent
{
//code
}


Public override void Display(int x) --Child
{
//Code
}

Here when you call Display method using child object it will calls the childs implementation

If you want to override a method you must define the method name in parent class with the virtual keyword.

Method Hiding

Rewriting a parent class method under the child class with out permission of parent is known as method hiding.

public void Show()   -------Parent
{
}


Public new void Show()--Child
{
//Code
}

Encapsulation: The process of wrapping up the data into single unit is known as Encapsulation.

Ex. Class is the best example because it hides every thing from outside.

DataAbstraction: It is the processing of representing essential feature with out representing the background details.

Ex. For a car driver he only needs to know about the how steering, accelerator,Gears and breaks work. He does not need to about how internal car engine works.


No comments:

Post a Comment