SlideShare a Scribd company logo

C++ oop

Sunil OS
Sunil OS

OOP and C++

1 of 37
www.SunilOS.com 1
www.sunilos.com
www.raystec.com
Object Oriented Programming
OOP……. Not OOPS!!
2
Object-Oriented Programming Concepts
What is an Object?
What is a Class?
Encapsulation?
Inheritance?
Polymorphism/Dynamic Binding?
Data Hiding?
Data Abstraction?
www.SunilOS.com
www.SunilOS.com 3
Custom Data Type
class Shape {
private:
int borderWidth = 0;
public:
int getBorderWidth() {
return borderWidth;
}
void setBorderWidth(int bw) {
borderWidth = bw;
}
};
:Shape
-color :String
-borderWidth:int
+getColor():String
+setColor()
+getBorderWidth():int
+setBorderWidth()
Members
Member
variables
Member
methods
www.SunilOS.com 4
Define attribute/variable
 void main(){
 Shape s;
 s.setBorderWidth(3);
 ….
 cout<<s.getBorderWidth();
}
S is an object here
Real World Entities – More Classes
www.SunilOS.com 5
:Automobile
-color :String
-speed:int
-make:String
+$NO_OF_GEARS
+getColor():String
+setColor()
+getMake():String
+setMake()
+break()
+changeGear()
+accelerator()
+getSpeed():int
:Person
-name:String
-dob : Date
-address:String
+$AVG_AGE
+getName():String
+setName()
+getAdress():String
+setAddress()
+getDob (): Date
+setDob ()
+getAge() : int
:Account
-number:String
-accountType : String
-balance:double
+getNumber():String
+setNumber()
+getAccountType():String
+setAccountType()
+deposit ()
+withdrawal ()
+getBalance():double
+fundTransfer()
+payBill()
www.SunilOS.com 6
Constructor
class Shape {
public Shape(){
cout<<“This is default
constructor”;
}
};
Shape s;
 Constructor is just like a method.
 It does not have return type.
 Its name is same as Class name.
 It is called at the time of object
calling.
 Constructors are used to initialize
instance/class variables.
 A class may have multiple
constructors with different number
of parameters.

Recommended

JavaScript
JavaScriptJavaScript
JavaScriptSunil OS
 
Variables in python
Variables in pythonVariables in python
Variables in pythonJaya Kumari
 
Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Deepak Singh
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 

More Related Content

What's hot

Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default argumentsNikhil Pandit
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJSunil OS
 
Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3Sunil OS
 
Async programming and python
Async programming and pythonAsync programming and python
Async programming and pythonChetan Giridhar
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))Papu Kumar
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
Collections Framework
Collections FrameworkCollections Framework
Collections FrameworkSunil OS
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Hibernate
Hibernate Hibernate
Hibernate Sunil OS
 

What's hot (20)

Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
C functions
C functionsC functions
C functions
 
Function in c program
Function in c programFunction in c program
Function in c program
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJ
 
Collection v3
Collection v3Collection v3
Collection v3
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Function
FunctionFunction
Function
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
 
Async programming and python
Async programming and pythonAsync programming and python
Async programming and python
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
Java operators
Java operatorsJava operators
Java operators
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Java Strings
Java StringsJava Strings
Java Strings
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Hibernate
Hibernate Hibernate
Hibernate
 

Similar to C++ oop

Similar to C++ oop (20)

Oops concept
Oops conceptOops concept
Oops concept
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
OOP Core Concept
OOP Core ConceptOOP Core Concept
OOP Core Concept
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
02.adt
02.adt02.adt
02.adt
 
C++ classes
C++ classesC++ classes
C++ classes
 
Object
ObjectObject
Object
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 

More from Sunil OS

Threads V4
Threads  V4Threads  V4
Threads V4Sunil OS
 
Threads v3
Threads v3Threads v3
Threads v3Sunil OS
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3Sunil OS
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )Sunil OS
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )Sunil OS
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )Sunil OS
 
Python Pandas
Python PandasPython Pandas
Python PandasSunil OS
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1Sunil OS
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays TechnologiesSunil OS
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and ConcurrencySunil OS
 

More from Sunil OS (20)

Threads V4
Threads  V4Threads  V4
Threads V4
 
DJango
DJangoDJango
DJango
 
PDBC
PDBCPDBC
PDBC
 
OOP v3
OOP v3OOP v3
OOP v3
 
Threads v3
Threads v3Threads v3
Threads v3
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays Technologies
 
C Basics
C BasicsC Basics
C Basics
 
Log4 J
Log4 JLog4 J
Log4 J
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 

Recently uploaded

Mycobacteriology update 2024 Margie Morgan.ppt
Mycobacteriology update 2024 Margie Morgan.pptMycobacteriology update 2024 Margie Morgan.ppt
Mycobacteriology update 2024 Margie Morgan.pptMargie Morgan
 
Nzinga Kika - The story of the queen
Nzinga Kika    -  The story of the queenNzinga Kika    -  The story of the queen
Nzinga Kika - The story of the queenDeanAmory1
 
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?Aggregage
 
Understanding Canada's international higher education landscape (2024)
Understanding Canada's international higher education landscape (2024)Understanding Canada's international higher education landscape (2024)
Understanding Canada's international higher education landscape (2024)CaraSkikne1
 
Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...Association for Project Management
 
2.22.24 Black Nationalism and the Nation of Islam.pptx
2.22.24 Black Nationalism and the Nation of Islam.pptx2.22.24 Black Nationalism and the Nation of Islam.pptx
2.22.24 Black Nationalism and the Nation of Islam.pptxMaryPotorti1
 
Google Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdfGoogle Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdfTechSoup
 
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...EduSkills OECD
 
EDL 290F Week 2 - Good Company (2024).pdf
EDL 290F Week 2  - Good Company (2024).pdfEDL 290F Week 2  - Good Company (2024).pdf
EDL 290F Week 2 - Good Company (2024).pdfElizabeth Walsh
 
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdfA Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdfOH TEIK BIN
 
Permeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery systemPermeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery systemchetanpatil2572000
 
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptxADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptxAKSHAYMAGAR17
 
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary  Education in LithuaniaAndreas Schleicher_ Strengthening Upper Secondary  Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary Education in LithuaniaEduSkills OECD
 
Add Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesAdd Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesCeline George
 
BBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptx
BBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptxBBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptx
BBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptxProf. Kanchan Kumari
 
Brochure-Project-tryve-elementary-dept..docx
Brochure-Project-tryve-elementary-dept..docxBrochure-Project-tryve-elementary-dept..docx
Brochure-Project-tryve-elementary-dept..docxAnnaLizaTadeo1
 
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...AKSHAYMAGAR17
 

Recently uploaded (20)

Mycobacteriology update 2024 Margie Morgan.ppt
Mycobacteriology update 2024 Margie Morgan.pptMycobacteriology update 2024 Margie Morgan.ppt
Mycobacteriology update 2024 Margie Morgan.ppt
 
Risk in the changing world – Opportunity or threat
Risk in the changing world – Opportunity or threatRisk in the changing world – Opportunity or threat
Risk in the changing world – Opportunity or threat
 
Nzinga Kika - The story of the queen
Nzinga Kika    -  The story of the queenNzinga Kika    -  The story of the queen
Nzinga Kika - The story of the queen
 
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
 
Understanding Canada's international higher education landscape (2024)
Understanding Canada's international higher education landscape (2024)Understanding Canada's international higher education landscape (2024)
Understanding Canada's international higher education landscape (2024)
 
Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...
 
2.22.24 Black Nationalism and the Nation of Islam.pptx
2.22.24 Black Nationalism and the Nation of Islam.pptx2.22.24 Black Nationalism and the Nation of Islam.pptx
2.22.24 Black Nationalism and the Nation of Islam.pptx
 
Lipids as Biopolymer
Lipids as Biopolymer Lipids as Biopolymer
Lipids as Biopolymer
 
Google Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdfGoogle Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdf
 
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
 
CLUBE PERLINGUAS .
CLUBE PERLINGUAS                        .CLUBE PERLINGUAS                        .
CLUBE PERLINGUAS .
 
EDL 290F Week 2 - Good Company (2024).pdf
EDL 290F Week 2  - Good Company (2024).pdfEDL 290F Week 2  - Good Company (2024).pdf
EDL 290F Week 2 - Good Company (2024).pdf
 
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdfA Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
 
Permeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery systemPermeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery system
 
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptxADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptx
 
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary  Education in LithuaniaAndreas Schleicher_ Strengthening Upper Secondary  Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
 
Add Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesAdd Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 Sales
 
BBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptx
BBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptxBBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptx
BBA 603 FUNDAMENTAL OF E- COMMERCE UNIT 1.pptx
 
Brochure-Project-tryve-elementary-dept..docx
Brochure-Project-tryve-elementary-dept..docxBrochure-Project-tryve-elementary-dept..docx
Brochure-Project-tryve-elementary-dept..docx
 
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
 

C++ oop

  • 2. 2 Object-Oriented Programming Concepts What is an Object? What is a Class? Encapsulation? Inheritance? Polymorphism/Dynamic Binding? Data Hiding? Data Abstraction? www.SunilOS.com
  • 3. www.SunilOS.com 3 Custom Data Type class Shape { private: int borderWidth = 0; public: int getBorderWidth() { return borderWidth; } void setBorderWidth(int bw) { borderWidth = bw; } }; :Shape -color :String -borderWidth:int +getColor():String +setColor() +getBorderWidth():int +setBorderWidth() Members Member variables Member methods
  • 4. www.SunilOS.com 4 Define attribute/variable  void main(){  Shape s;  s.setBorderWidth(3);  ….  cout<<s.getBorderWidth(); } S is an object here
  • 5. Real World Entities – More Classes www.SunilOS.com 5 :Automobile -color :String -speed:int -make:String +$NO_OF_GEARS +getColor():String +setColor() +getMake():String +setMake() +break() +changeGear() +accelerator() +getSpeed():int :Person -name:String -dob : Date -address:String +$AVG_AGE +getName():String +setName() +getAdress():String +setAddress() +getDob (): Date +setDob () +getAge() : int :Account -number:String -accountType : String -balance:double +getNumber():String +setNumber() +getAccountType():String +setAccountType() +deposit () +withdrawal () +getBalance():double +fundTransfer() +payBill()
  • 6. www.SunilOS.com 6 Constructor class Shape { public Shape(){ cout<<“This is default constructor”; } }; Shape s;  Constructor is just like a method.  It does not have return type.  Its name is same as Class name.  It is called at the time of object calling.  Constructors are used to initialize instance/class variables.  A class may have multiple constructors with different number of parameters.
  • 7. www.SunilOS.com 7 Multiple Constructors One class may have more than one constructors. Multiple constructors are used to initialize different sets of class attributes. When a class has more than one constructors, it is called Constructor Overloading. Constructors those receive parameters are called Parameterized Constructors.
  • 8. www.SunilOS.com 8 Constructors Overloading class Shape { public : Shape(){ cout<<“This is default constuctor”; } Shape(int a){ cout<<a; } Shape s ; Or Shape s1(5);
  • 9. Default Constructor  Default constructor does not receive any parameter. o public Shape(){ .. }  If User does not define any constructor then Default Constructor will be created by Compiler.  But if user defines single or multiple constructors then default constructor will not be generated by Compiler. www.SunilOS.com 9
  • 10. Destructor It is inverse of constructor function. It is used to deallocate the memory or release the resources like closing files. It is called when object is destroyed. It has a same name as class name used tilde(~) as prefix. ~class_name(){…….} www.SunilOS.com 10
  • 11. Copy Constructor It is a special type of constructor . It is used to create new object as a copy of existing object. It is a standard way to copy an object. It is used to initialize one object from another object of the same type. www.SunilOS.com 11
  • 12. Copy Constructor… class CopyCon{ private : int a1; public: CopyCon(){} CopyCon(int a){ a1 = a; } void display(){ cout<<a1; } }; www.SunilOS.com 12 void main(){ clrscr(); CopyCon c(2); CopyCon c1 = c; c.display(); c1.display(); getch(); }
  • 13. Operator Overloading Built-in operators can be redefined & overloaded. Overloaded operators are functions with special names. It is used to perform operations on user defined data type.  + operator overloaded on two integer values to perform addition.  + operator overloaded on two string values to perform concatenation. www.SunilOS.com 13
  • 14. return_type operator sign(){} void operator +() { count=count+1; } www.SunilOS.com 14
  • 15.  class temp { private: int count; public: temp():count(5){ } void operator ++() { count=count+1; } void Display() { cout<<"Count: "<<count; } }; www.SunilOS.com 15 int main() { temp t; ++t; t.Display(); return 0; }
  • 16. Operators that cannot be overloaded scope operator - :: sizeof member selector - . member pointer selector - * ternary operator - ?: www.SunilOS.com 16
  • 17. Scope Resolution Operator :: It is used to qualify hidden name. When local variable and global variable are having same name, local variable gets the priority. C++ allows flexibility of accessing both the variables through a scope resolution operator. www.SunilOS.com 17
  • 18. int a = 10; void main(){ o int a = 15; o cout<<a<<::a; o ::a=20; o Cout<<a<<::a; } Output :15 10  15 20 www.SunilOS.com 18
  • 19. OOP Key Concepts Encapsulation: o Creates Expert Classes. Inheritance: o Creates Specialized Classes. Polymorphism: o Provides Dynamic behaviour at Runtime. www.SunilOS.com 19
  • 20. www.SunilOS.com 20 Encapsulation Gathering all related methods and attributes in a Class is called encapsulation. Often, for practical reasons, an object may wish to expose some of its variables or hide some of its methods. Access Levels: Modifier Class Subclass Packag e World private X protected X X X public X X X X
  • 21. Friend Function There is a mechanism in C++ to access private & protected members of a class. This mechanism is known as friend function or friend class. We have to use friend keyword in prefix of function name. Declaration should be inside the class body starting with keyword friend. www.SunilOS.com 21
  • 22.  class Distance { o private: o int meter; o public: o Distance(): meter(0){ } o friend int func(Distance); //friend function  };  int func(Distance d) {//function definition o d.meter=5; //accessing private data from non-member function o return d.meter;  } int main() { o Distance D; o cout<<"Distace: "<<func(D); o return 0;  } www.SunilOS.com 22
  • 24. www.SunilOS.com 24 Inheritance :Shape color :String borderWidth:int getColor():String setColor() getBorderWidth():int setBorderWidth() :Rectangle length :int width:int area() getLength() setLength() :Circle radius : int area() getRadius() setRadius() :Triangle base:int hight:int area() getBase() setBase() Circle c ; c.getColor(); c.getBorderWidth(); c.area(); UML Notation
  • 26. Polymorphism One thing with multiple forms. Two types of polymorphism Static Polymorphism(Overloading) Dynamic Polymorphism(Overriding) Ways to Provide polymorphism: o Through Interfaces. o Method Overriding. o Method Overloading. www.SunilOS.com 26
  • 27. www.SunilOS.com 27 Method Overriding – area() :Shape Color :String borderWidth:int getColor():String setColor() getBorderWidth():int setBorderWidth() area() :Rectangle length :int width:int area() getLength() setLength() :Circle radius area() getRadius() setRadius() :Triangle base:int hight:int area() getBase() setBase() Shape s; s.getColor(); s.getBorderWidth(); s.area();
  • 28. www.SunilOS.com 28 Abstract Class  What code can be written in Shape.area() method? o Nothing, area() method is defined by child classes. It should have only declaration.  Is Shape a concrete class? o NO, Rectangle, Circle and Triangle are concrete classes.  If it has only area declaration then o Class will be abstract.  Benefit? o Parent will enforce child to implement area() method. o Child has to mandatorily define (implement) area method. o This will achieve polymorphism.
  • 29. www.SunilOS.com 29 Shape class Shape { private: int borderWidth = 0; public : double area(); int getBorderWidth() { return borderWidth; } };
  • 30. www.SunilOS.com 30 Interface / Virtual function A class is made abstract by declaring at least one of its functions as pure virtual function A pure virtual function is specified by placing "= 0" in its declaration public: virtual double area() = 0;
  • 33. Data Abstraction ( Cont. ) Data abstraction is the way to create complex data types and exposing only meaningful operations to interact with data type, whereas hiding all the implementation details from outside world. Data Abstraction is a process of hiding the implementation details and showing only the functionality. Data Abstraction in java is achieved by interfaces and abstract classes. www.SunilOS.com 33
  • 35. Data Hiding ( Cont. ) Data Hiding is an aspect of Object Oriented Programming (OOP) that allows developers to protect private data and hide implementation details. Developers can hide class members from other classes. Access of class members can be restricted or hide with the help of access modifiers. www.SunilOS.com 35
  • 36. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 36