2. OOP CONCEPTS
Object Oriented Programming is paradigm or methodology in which we
write programs using Classes and Objects.
There are 4 OOP concepts:
• Inheritance
• Abstraction
• Encapsulation
• Polymorphism
3. INHERITANCE
• When one entity acquires
properties of one or more
another entities is called
Inheritance
• It is same like Biological
Inheritance in which child
extract features of mother and
father i.e parents
4. ENCAPLSULATION
• Binding data and code together
into a single unit
• example: Class of C++
• see class is collection of
methods and variables. means
variables and methods are
binded inside the class that
means it is encapsulated inside
the class as we observe the
diagram.
5. POLYMORPHISM
• When one task is performed in
more than one ways
• example: languages of different
people of countries means all
the humans in world
communicate with each other
but in their languages so here
task is to communicate and in
different languages are many
ways.
6. ABSTRACTION
• It is used for hiding internal
details but showing only the
functionality
• example: phone call process
here we dont know how signal
goes from one phone to another
and how communication happens.
we just know how to call and dont
bother about internal processing
of call . That's simple.
7. CLASS
• a template or blueprint from which objects are created
• collection of data members and member functions
• syntax of writing a class:
class classname
{
data members1,2,.....; //variables
member function1(){}
member function2(){}
}
8. OBJECT
• a run time and real world entity
• entity that has state and behaviour
• instance of class
• syntax of creating a object:
classname objectname/reference variable1;
classname objectname/reference variable2;
classname objectname/reference variable3;
and so on
9. EXAMPLE OF HOW TO WRITE A CLASS AND HOW TO CREATE OBJECT
class Dog{
String breed;
String color;
int height;
int weight;
void run()
{
cout<<”running”;
}
}
void main()
{
Dog d1;
Dog d2;
d1.run(); // how to call a function: USING (.) operator: objectname.functionname();
d2.run();
}