Object Oriented Programming Synopsis
Object Oriented Programming Synopsis
Polymorphism
Encapsulation
Encapsulation is process of keeping data
and methods together inside objects.
encapsulation is realized through the
classes. A Class can contain data and
methods.
Lke Employee class will provide properties
(Name,Age ....) as well as actions
(Calculatesalary, GoonLeave....) of the
employee entity.
get
{
return(acc_id);
}
}
}
}
}
Constructor and Destructor
Constructor is special function that is called automatically
whenever new instance is created.
It is used to initialize the values for class data member.
There can be any number of constructors in a program but
must be differ in terms of their parameters, Called as
Overloaded constructor.
Note :- The name of Constructor and Destructor must be the same name
as Class name where both never return any value.
Constructor can take one or more parameters but destructor can not.
Destructor starts with (~) titles character.
Account() //Default
{
}
~Account() //Destructor
{
}
Objects
Object is an instance of a type or
class.
public int i;
}
Child Class
Class12
Hierarchical
Child1 Child2
Child1 Child2
Multiple
Child12
Child11
message=msg;
}
interface Interdemo
{ void Show();}
interface Interdemo1
{ void Show();}
class Interclash:Interdemo,Interdemo1
{ void Interdemo.Show() {
Console.WriteLine("Show() method Implemented"); }
void Interdemo1.Show() {
Console.WriteLine("Display() method Implemented"); }
This gives the operator more than one meaning, or "overloads" it. The
compiler distinguishes between the different meanings of an
operator by examining the types of its operands.
public op_cls()
{
num1=0;
}
obj3.num1=obj1.num1+obj2.num1;
return(obj3);
}
}
Using Overloaded Operator
op_cls o1=new op_cls(100);
op_cls o2=new 0p_cls(200);
o3=o1+o2;
o3.show(); //300
Overloadable Operators