SlideShare a Scribd company logo
1 of 22
Introduction to Object
Oriented Programming
Language (OOPS) in C++
PROGRAMMING PARADIGM
Programming
Paradigms
Imperative
Programming
Procedural (C)
Object Oriented
Programming
(C++, Java)
Declarative
Programming
Functional
(Haskell)
Logic (Prolog)
STRUCTURED/ PROCEDURAL LANGUAGE
TOP- DOWN
APPROACH
PROGRAM
MODULE 1
MODULE 3 MODULE 4
MODULE 2
MODULE 5
EXAMPLES OF
STRUCTURED
LANGUAGE
FORTRAN
PASCAL
ALGOL
COBOL
BASIC
C
WHAT IS
OOP stands for Object-Oriented Programming
Features of OOPS
Encapsulation
Abstraction
Inheritance
Polymorphism
1. ENCAPSULATION
It is a process of wrapping of data and methods in a single unit
CLASS and OBJECT
CLASS OBJECT
Class is a container which collects
variables and methods
Object is an instance of a class
It is mere a blueprint to which no
memory is allocated at the time of
declaration
Sufficient memory space will be
allocated for the variables of class
at the time of declaration
One class definition should exist
only once in the program
For one class multiple objects can
be created.
SYNTAX:
CLASS OBJECT
class class_name
{
access specifier:
data members;
member funtions()
};
class_name object_reference;
<header files>
class addition
{ private:
int a, b, sum;
public:
void input()
{
cout<< “Enter two numbers”;
cin>>a>>b;
}
void add()
{
sum=a+b;
}
void output()
{
cout<< “Sum of two number is= “<<sum;
}
};
void main()
{
addition ob;
ob. input();
ob. add();
ob.output();
getch();
}
Enter two numbers
10
20
Sum of two number is= 30
OUTPUT
Data members
Input() add() output() are the
member functions
Object
initialization
Dot operator is
used for calling
<header files>
class addition
{
int a, b, sum;
public:
void add()
{
cout<< “Enter two numbers”;
cin>>a>>b;
sum=a+b;
cout<< “Sum of two number is= “<<sum;
}
};
void main()
{
clrscr();
addition ob;
ob. add();
getch();
}
Enter two numbers
10
20
Sum of two number is= 30
OUTPUT
2. Abstraction
Abstraction means displaying only essential information and
hiding the details
<header files>
class addition
{
int a, b, sum;
public:
void add()
{
cout<< “Enter two numbers”;
cin>>a>>b;
sum=a+b;
cout<< “Sum of two number is=
“<<sum;
}
};
void main()
{
addition ob;
ob. a= 10;
ob. b=20;
ob. add();
getch();
}
Using Access Specifier in
Class
Public:
Accessible
both inside
and outside
the class
Private:
Accessible
inside the
class but not
outside the
class
Protected:
accessible
inside the
class and
only in
inherited
classes
//Error; a and b not accessible
outside the class because they
are declared private
3. INHERITANCE
It is a mechanism in which one class acquires the property of another class.
Derived Class (child)
• The class that inherits
from another class
Base Class (Parent)
• The class being
inherited from
Syntax:
class base_class
{
//Body of base class
};
class derived_class : access_specifier base_class
{
//Body of derived class
};
Base Class
Derived Class
4. Polymorphism
Polymorphism means "one interface, multiple forms"
class Animal {
public:
void animalSound() {
cout << "The animal makes a sound n" ;
}
};
class Pig : public Animal {
public:
void animalSound() {
cout << "The pig says: wee wee n" ;
}
};
class Dog : public Animal {
public:
void animalSound() {
cout << "The dog says: bow wow n" ;
}
};
void main() {
Animal myAnimal;
Pig myPig;
Dog myDog;
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
}
OUTPUT
The animal makes a sound
The pig says: wee wee
The dog says: bow wow
Base Class (Animal)
Derived Class (Pig)
Derived Class (Dog)
class Animal {
public:
void animalSound() {
cout << "The animal makes a sound n" ;
}
};
class Pig : public Animal {
public:
void animalSound() {
cout << "The pig says: wee wee n" ;
}
};
class Dog : public Animal {
public:
void animalSound() {
cout << "The dog says: bow wow n" ;
}
};
void main() {
Animal myAnimal;
Pig myPig;
Dog myDog;
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
}
OUTPUT
The animal makes a sound
The pig says: wee wee
The dog says: bow wow
Base Class (Animal)
Derived Class (Pig)
Derived Class (Dog)
Conclusion
Structured Programming
..
.. ..
..
..

More Related Content

What's hot

Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop Kumar
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMoutaz Haddara
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4MOHIT TOMAR
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS abhishek kumar
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Paumil Patel
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java yash jain
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingIqra khalil
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaGlenn Guden
 

What's hot (20)

OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
JDBC
JDBCJDBC
JDBC
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Inheritance
InheritanceInheritance
Inheritance
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java
 
Java Beans
Java BeansJava Beans
Java Beans
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 

Similar to Concept of OOPS with real life examples (20)

inheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdfinheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
Concepts of oop1
Concepts of oop1Concepts of oop1
Concepts of oop1
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
oop.pptx
oop.pptxoop.pptx
oop.pptx
 
EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java
JavaJava
Java
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Inheritance (with classifications)
Inheritance (with classifications)Inheritance (with classifications)
Inheritance (with classifications)
 
Inheritance
Inheritance Inheritance
Inheritance
 
Oops
OopsOops
Oops
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
Inheritance
InheritanceInheritance
Inheritance
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 
inheritance
inheritanceinheritance
inheritance
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
OOP.ppt
OOP.pptOOP.ppt
OOP.ppt
 

Recently uploaded

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 

Recently uploaded (20)

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 

Concept of OOPS with real life examples

  • 1. Introduction to Object Oriented Programming Language (OOPS) in C++
  • 2. PROGRAMMING PARADIGM Programming Paradigms Imperative Programming Procedural (C) Object Oriented Programming (C++, Java) Declarative Programming Functional (Haskell) Logic (Prolog)
  • 3. STRUCTURED/ PROCEDURAL LANGUAGE TOP- DOWN APPROACH PROGRAM MODULE 1 MODULE 3 MODULE 4 MODULE 2 MODULE 5
  • 5. WHAT IS OOP stands for Object-Oriented Programming
  • 7. 1. ENCAPSULATION It is a process of wrapping of data and methods in a single unit
  • 8. CLASS and OBJECT CLASS OBJECT Class is a container which collects variables and methods Object is an instance of a class It is mere a blueprint to which no memory is allocated at the time of declaration Sufficient memory space will be allocated for the variables of class at the time of declaration One class definition should exist only once in the program For one class multiple objects can be created.
  • 9.
  • 10.
  • 11. SYNTAX: CLASS OBJECT class class_name { access specifier: data members; member funtions() }; class_name object_reference;
  • 12. <header files> class addition { private: int a, b, sum; public: void input() { cout<< “Enter two numbers”; cin>>a>>b; } void add() { sum=a+b; } void output() { cout<< “Sum of two number is= “<<sum; } }; void main() { addition ob; ob. input(); ob. add(); ob.output(); getch(); } Enter two numbers 10 20 Sum of two number is= 30 OUTPUT Data members Input() add() output() are the member functions Object initialization Dot operator is used for calling
  • 13. <header files> class addition { int a, b, sum; public: void add() { cout<< “Enter two numbers”; cin>>a>>b; sum=a+b; cout<< “Sum of two number is= “<<sum; } }; void main() { clrscr(); addition ob; ob. add(); getch(); } Enter two numbers 10 20 Sum of two number is= 30 OUTPUT
  • 14. 2. Abstraction Abstraction means displaying only essential information and hiding the details
  • 15. <header files> class addition { int a, b, sum; public: void add() { cout<< “Enter two numbers”; cin>>a>>b; sum=a+b; cout<< “Sum of two number is= “<<sum; } }; void main() { addition ob; ob. a= 10; ob. b=20; ob. add(); getch(); } Using Access Specifier in Class Public: Accessible both inside and outside the class Private: Accessible inside the class but not outside the class Protected: accessible inside the class and only in inherited classes //Error; a and b not accessible outside the class because they are declared private
  • 16. 3. INHERITANCE It is a mechanism in which one class acquires the property of another class. Derived Class (child) • The class that inherits from another class Base Class (Parent) • The class being inherited from
  • 17.
  • 18. Syntax: class base_class { //Body of base class }; class derived_class : access_specifier base_class { //Body of derived class }; Base Class Derived Class
  • 19. 4. Polymorphism Polymorphism means "one interface, multiple forms"
  • 20. class Animal { public: void animalSound() { cout << "The animal makes a sound n" ; } }; class Pig : public Animal { public: void animalSound() { cout << "The pig says: wee wee n" ; } }; class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow n" ; } }; void main() { Animal myAnimal; Pig myPig; Dog myDog; myAnimal.animalSound(); myPig.animalSound(); myDog.animalSound(); } OUTPUT The animal makes a sound The pig says: wee wee The dog says: bow wow Base Class (Animal) Derived Class (Pig) Derived Class (Dog)
  • 21. class Animal { public: void animalSound() { cout << "The animal makes a sound n" ; } }; class Pig : public Animal { public: void animalSound() { cout << "The pig says: wee wee n" ; } }; class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow n" ; } }; void main() { Animal myAnimal; Pig myPig; Dog myDog; myAnimal.animalSound(); myPig.animalSound(); myDog.animalSound(); } OUTPUT The animal makes a sound The pig says: wee wee The dog says: bow wow Base Class (Animal) Derived Class (Pig) Derived Class (Dog)