Object Oriented Programming:
-Traditional languages like "C" are known to be Procedural languages which doesn't provide the features likes Code Security and Code Re-usability.
-Traditional languages like "C" are known to be Procedural languages which doesn't provide the features likes Code Security and Code Re-usability.
-To provide the above features a new approach in programming has been introduced as Object Oriented Approach.
-OOP languages supports security and re-usability, to call a language as object oriented it needs to satisfy the following principles:
-Abstraction
-Encapsulation
-Inheritance
-Polymorphism
-Abstraction
-Encapsulation
-Inheritance
-Polymorphism
Abstraction: this principles talks about hiding of the complexity by providing the user with a set of interfaces to drive the functionalities.
Encapsulation: this principles talks about wrapping of the code under a container known as "Class" which is going to protect the content inside, as wrappers always protect the content in them.
Inheritance: according to this principles if there is a parent child relationship between any 2 the property of the parent can be acquired by their children, so in the same way if u can establish parent child relationships between classes, the code in 1 class can be consumed in the other, also referred as reusability of the code.
Polymorphism: Entities behaving in different ways depending upon the input they recieve is known as polymorphism, which allows you to give the same name for more than 1 method present in a class.
-------------------------------------------------------------------------------------
Defining methods under a class:
[<modifiers>] <void | type> <Name> ( [<params>] )
{
<Stmts>;
}
-------------------------------------------------------------------------------------
Defining methods under a class:
[<modifiers>] <void | type> <Name> ( [<params>] )
{
<Stmts>;
}
Params are passed as following:
[ref] <type> <var> [,...n]
[ref] <type> <var> [,...n]
//No Input & Output
void Test1()
{
Console.WriteLine("First Method");
}
void Test1()
{
Console.WriteLine("First Method");
}
//No Output Has Input
void Test2(int x)
{
Console.WriteLine("Second Method: " + x);
}
void Test2(int x)
{
Console.WriteLine("Second Method: " + x);
}
//No Input Has Output
string Test3()
{
return "Third Method";
}
string Test3()
{
return "Third Method";
}
//Has Input & Output
string Test4(string name)
{
return "Hello " + name;
}
string Test4(string name)
{
return "Hello " + name;
}
//Returns multiple values
int Test5(int x, int y, ref int z)
{
z = x * y;
return x + y;
}
int Test5(int x, int y, ref int z)
{
z = x * y;
return x + y;
}
a = p.Test5(100, 25, ref b);
<class> <obj> = [ new <class>( [<arglist>] ) ]
Program p; //p is a variable
p = new Program(); //p is a object
or
Program p = new Program(); //p is a object
p = new Program(); //p is a object
or
Program p = new Program(); //p is a object
Note: The object of the class in java & .net programming languages gets created only with the use of "new" keyword, if new is not used it is considered as a variable of the class which will not occupy any space in the memory.
No comments:
Post a Comment