SlideShare a Scribd company logo
1 of 20
   Object-oriented programming (OOP) is a
    programming paradigm using “objects”

   An object is an identifiable entity with some
    characteristics and behaviour.

   Very different approach than function-based
    programming (like C).
 A class definition begins with the keyword class.
 The body of the class is contained within a set of

  braces, { } ; (notice the semi-colon).



                   class class_name       Any valid
                   }                      identifier
                   .…
                   .…
                                      Class body (data member
                   .…
                                      + methods)
                                        methods
                   ;{
   Within the body, the keywords private: and public:
    specify the access level of the members of the
    class.
    ◦ the default is private.

   Usually, the data members of a class are declared
    in the private: section of the class and the member
    functions are in public: section.
class class_name
}
:private
          …        private members or
          …        methods
          …
    public:
          …
          …        Public members or methods
          …
;{
   Member access specifiers
    ◦ public:
      can be accessed outside the class directly.
          The public stuff is the interface.
    ◦ private:
      Accessible only to member functions of class
      Private members and methods are for internal use only.
   This class example shows how we can
    encapsulate (gather) a circle information into one
    package (unit or class)
                                            No need for others classes to
     class Circle                           access and retrieve its value
                                            directly. The
     {
                                            class methods are responsible for
        private:                            that only.
              double radius;
        public:
              void setRadius(double r);    They are accessible from outside
     double getDiameter();                 the class, and they can access the
              double getArea();            member (radius)
              double getCircumference();
     };
   Declaring a variable of a class type creates an
    object. You can have many variables of the
    same type (class).
    ◦ Instantiation
 Once an object of a certain class is instantiated,
  a new memory location is created for it to store
  its data members and code
 You can instantiate many objects from a class
  type.
    ◦ Ex) Circle c; Circle *c;
   Constructor:
    ◦   Public function member.
    ◦   Called when a new object is created (instantiated).
    ◦   Initialize data members.
    ◦   Same name as class.
    ◦   No return type.
    ◦   They can be overloaded.
class Circle
                                      Constructor with no
{
                                      argument
   private:
         double radius;
   public:                            Constructor with one
         Circle();                    argument
         Circle(int r);
          void setRadius(double r);
         double getDiameter();
         double getArea();
         double getCircumference();
};
 Class implementation: writing the code of class
  methods.
 There are two ways:

    ◦ Member functions defined outside class
        Using Binary scope resolution operator (::)
        “Ties” member name to class name
        Uniquely identify functions of particular class
        Different classes can have member functions with same
         name
    ◦ Format for defining member functions
        ReturnType ClassName::MemberFunctionName( )
        {
         …
        }
2.       Member functions defined inside class
     ◦     Do not need scope resolution operator, class name;



            class Circle
            {                                                   Defined
               private:                                         inside
                     double radius;                             class
               public:
                     Circle() { radius = 0.0;}
                     Circle(int r);
                     void setRadius(double r){radius = r;}
                     double getDiameter(){ return radius *2;}
                     double getArea();
                     double getCircumference();
            };
class Circle
{
   private:
          double radius;
   public:
          Circle() { radius = 0.0;}
          Circle(int r);
          void setRadius(double r){radius = r;}
          double getDiameter(){ return radius *2;}
          double getArea();
          double getCircumference();
};
Circle::Circle(int r)
{
                                                     Defined outside class
   radius = r;
}
double Circle::getArea()
{
   return radius * radius * (22.0/7);
}
double Circle:: getCircumference()
{
   return 2 * radius * (22.0/7);
}
   Operators to access class members
    ◦ Identical to those for struct
    ◦ Dot member selection operator (.)
      Object
      Reference to object
    ◦ Arrow member selection operator (->)
      Pointers
class Circle
{
   private:
          double radius;
   public:                                                           The first constructor
          Circle() { radius = 0.0;} // DC                            being called and the
          Circle(int r); // Parameterised constructure              second parameterised
                                                                     constructor is called
          void setRadius(double r){radius = r;}                           after that.
          double getDiameter(){ return radius *2;}
          double getArea();
          double getCircumference();       void main()                 Since radius is a
};                                         {                             private class
Circle::Circle(int r)                           Circle c1,c2(7);        data member
{
   radius = r;                                  cout<<“The area of c1:”
                                                     <<c1.getArea()<<“n”;
}
double Circle::getArea()                        //c1.radius= 5;//syntax error
{                                               c1.setRadius(5);
   return radius * radius * (22.0/7);
}                                               cout<<“The circumference of c1:”
double Circle:: getCircumference()                  << c1.getCircumference()<<“n”;
{
   return 2 * radius * (22.0/7);                cout<<“The Diameter of c2:”
                                                    <<c2.getDiameter()<<“n”;
}                                          }
class Circle
{
   private:
          double radius;
   public:
          Circle() { radius = 0.0;}
          Circle(int r);
          void setRadius(double r){radius = r;}
          double getDiameter(){ return radius *2;}
          double getArea();
          double getCircumference();
};
Circle::Circle(int r)                 void main()
                                      {
{
                                            Circle c(7);
   radius = r;                              Circle *cp1 = &c;
}                                           Circle *cp2 = new Circle(7);
double Circle::getArea()
{                                           cout<<“The are of cp2:”
   return radius * radius * (22.0/7);                  <<cp2->getArea();
}
double Circle:: getCircumference() }
{
   return 2 * radius * (22.0/7);
}
   Destructors
    ◦ Special member function
    ◦ Same name as class
         Preceded with tilde (~)
    ◦   No arguments
    ◦   No return value
    ◦   Cannot be overloaded
    ◦   Before system reclaims object’s memory
         Reuse memory for new objects
         Mainly used to de-allocate dynamic memory locations
1. Simplifies programming
2. Interfaces
      Information hiding:
       Implementation details hidden within classes themselves
1. Software reuseability
      Class objects included as members of other classes
Oo ps

More Related Content

What's hot

Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1Vineeta Garg
 
Defining classes-part-i-constructors-properties
Defining classes-part-i-constructors-propertiesDefining classes-part-i-constructors-properties
Defining classes-part-i-constructors-propertiesCtOlaf
 
V8 hidden class and inline cache
V8 hidden class and inline cacheV8 hidden class and inline cache
V8 hidden class and inline cacheFanis Prodromou
 
Gazr
GazrGazr
Gazrkuro7
 
The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202Mahmoud Samir Fayed
 
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...Khoa Nguyen
 
Unit3 java
Unit3 javaUnit3 java
Unit3 javamrecedu
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classesKumar
 
The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202Mahmoud Samir Fayed
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in javaHarish Gyanani
 
The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185Mahmoud Samir Fayed
 
Modul Praktek Java OOP
Modul Praktek Java OOP Modul Praktek Java OOP
Modul Praktek Java OOP Zaenal Arifin
 
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...JSFestUA
 

What's hot (20)

Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Op ps
Op psOp ps
Op ps
 
Defining classes-part-i-constructors-properties
Defining classes-part-i-constructors-propertiesDefining classes-part-i-constructors-properties
Defining classes-part-i-constructors-properties
 
V8 hidden class and inline cache
V8 hidden class and inline cacheV8 hidden class and inline cache
V8 hidden class and inline cache
 
PHP OOP
PHP OOPPHP OOP
PHP OOP
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
Inheritance
InheritanceInheritance
Inheritance
 
Gazr
GazrGazr
Gazr
 
The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202
 
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...
 
Unit3 java
Unit3 javaUnit3 java
Unit3 java
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classes
 
Chapter ii(oop)
Chapter ii(oop)Chapter ii(oop)
Chapter ii(oop)
 
Ch2 Liang
Ch2 LiangCh2 Liang
Ch2 Liang
 
The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in java
 
The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185
 
Modul Praktek Java OOP
Modul Praktek Java OOP Modul Praktek Java OOP
Modul Praktek Java OOP
 
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
 

Viewers also liked

Human resource at taj palace
Human resource at taj palaceHuman resource at taj palace
Human resource at taj palaceLal Sivaraj
 
Cj industries supply chain management
Cj industries supply chain managementCj industries supply chain management
Cj industries supply chain managementLal Sivaraj
 
MitM on USB -- Introduction of USBProxy --
MitM on USB -- Introduction of USBProxy --MitM on USB -- Introduction of USBProxy --
MitM on USB -- Introduction of USBProxy --Kiyotaka Atsumi
 
Mergers & acquisitions pharma industry
Mergers & acquisitions pharma industryMergers & acquisitions pharma industry
Mergers & acquisitions pharma industryLal Sivaraj
 
Deming prize and sona koyo
Deming prize and sona koyoDeming prize and sona koyo
Deming prize and sona koyoLal Sivaraj
 
Project on indian automotive industry
Project on indian automotive industryProject on indian automotive industry
Project on indian automotive industryLal Sivaraj
 
Bài 2 thị trường- cung và cầu
Bài 2  thị trường- cung và cầuBài 2  thị trường- cung và cầu
Bài 2 thị trường- cung và cầuQuyen Le
 
Bài 4: Lý thuyết chung về doanh nghiệp
Bài 4:  Lý thuyết chung về doanh nghiệpBài 4:  Lý thuyết chung về doanh nghiệp
Bài 4: Lý thuyết chung về doanh nghiệpQuyen Le
 
Bài 1 giới thiệu ktvm
Bài 1  giới thiệu ktvmBài 1  giới thiệu ktvm
Bài 1 giới thiệu ktvmQuyen Le
 
Bài 3 lựa chọn của người tiêu dùng và cầu thị trường
Bài 3  lựa chọn của người tiêu dùng và cầu thị trườngBài 3  lựa chọn của người tiêu dùng và cầu thị trường
Bài 3 lựa chọn của người tiêu dùng và cầu thị trườngQuyen Le
 
Bài 7 điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trường
Bài 7  điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trườngBài 7  điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trường
Bài 7 điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trườngQuyen Le
 
20130601.gpgpu勉強会 ポータブルスパコン製作顛末記
20130601.gpgpu勉強会 ポータブルスパコン製作顛末記20130601.gpgpu勉強会 ポータブルスパコン製作顛末記
20130601.gpgpu勉強会 ポータブルスパコン製作顛末記Kiyotaka Atsumi
 

Viewers also liked (19)

Sorting searching
Sorting searchingSorting searching
Sorting searching
 
Hodder
HodderHodder
Hodder
 
Human resource at taj palace
Human resource at taj palaceHuman resource at taj palace
Human resource at taj palace
 
Cj industries supply chain management
Cj industries supply chain managementCj industries supply chain management
Cj industries supply chain management
 
MitM on USB -- Introduction of USBProxy --
MitM on USB -- Introduction of USBProxy --MitM on USB -- Introduction of USBProxy --
MitM on USB -- Introduction of USBProxy --
 
Blog management
Blog managementBlog management
Blog management
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Coca cola
Coca colaCoca cola
Coca cola
 
Mergers & acquisitions pharma industry
Mergers & acquisitions pharma industryMergers & acquisitions pharma industry
Mergers & acquisitions pharma industry
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Deming prize and sona koyo
Deming prize and sona koyoDeming prize and sona koyo
Deming prize and sona koyo
 
Oscillators
OscillatorsOscillators
Oscillators
 
Project on indian automotive industry
Project on indian automotive industryProject on indian automotive industry
Project on indian automotive industry
 
Bài 2 thị trường- cung và cầu
Bài 2  thị trường- cung và cầuBài 2  thị trường- cung và cầu
Bài 2 thị trường- cung và cầu
 
Bài 4: Lý thuyết chung về doanh nghiệp
Bài 4:  Lý thuyết chung về doanh nghiệpBài 4:  Lý thuyết chung về doanh nghiệp
Bài 4: Lý thuyết chung về doanh nghiệp
 
Bài 1 giới thiệu ktvm
Bài 1  giới thiệu ktvmBài 1  giới thiệu ktvm
Bài 1 giới thiệu ktvm
 
Bài 3 lựa chọn của người tiêu dùng và cầu thị trường
Bài 3  lựa chọn của người tiêu dùng và cầu thị trườngBài 3  lựa chọn của người tiêu dùng và cầu thị trường
Bài 3 lựa chọn của người tiêu dùng và cầu thị trường
 
Bài 7 điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trường
Bài 7  điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trườngBài 7  điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trường
Bài 7 điều tiết của chính phủ và ảnh hưởng của ngoại thương đến thị trường
 
20130601.gpgpu勉強会 ポータブルスパコン製作顛末記
20130601.gpgpu勉強会 ポータブルスパコン製作顛末記20130601.gpgpu勉強会 ポータブルスパコン製作顛末記
20130601.gpgpu勉強会 ポータブルスパコン製作顛末記
 

Similar to Oo ps

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsFALLEE31188
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
C++ Classes Tutorials.ppt
C++ Classes Tutorials.pptC++ Classes Tutorials.ppt
C++ Classes Tutorials.pptaasuran
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their AccessingMuhammad Hammad Waseem
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#ANURAG SINGH
 
Chapter22 static-class-member-example
Chapter22 static-class-member-exampleChapter22 static-class-member-example
Chapter22 static-class-member-exampleDeepak Singh
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.pptDeepVala5
 
Chapter19 constructor-and-destructor
Chapter19 constructor-and-destructorChapter19 constructor-and-destructor
Chapter19 constructor-and-destructorDeepak Singh
 
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 & objectsRai University
 
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 & objectsRai University
 
Lecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCESLecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCESUzairSaeed18
 

Similar to Oo ps (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
C++ classes
C++ classesC++ classes
C++ classes
 
C++ classes
C++ classesC++ classes
C++ classes
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C++ Classes Tutorials.ppt
C++ Classes Tutorials.pptC++ Classes Tutorials.ppt
C++ Classes Tutorials.ppt
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#
 
Chapter22 static-class-member-example
Chapter22 static-class-member-exampleChapter22 static-class-member-example
Chapter22 static-class-member-example
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.ppt
 
Chapter19 constructor-and-destructor
Chapter19 constructor-and-destructorChapter19 constructor-and-destructor
Chapter19 constructor-and-destructor
 
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
 
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
 
oop objects_classes
oop objects_classesoop objects_classes
oop objects_classes
 
Lecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCESLecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCES
 
Java Classes
Java ClassesJava Classes
Java Classes
 
3433 Ch09 Ppt
3433 Ch09 Ppt3433 Ch09 Ppt
3433 Ch09 Ppt
 

More from ForwardBlog Enewzletter (6)

Pn junction
Pn junctionPn junction
Pn junction
 
Feedback amplifiers
Feedback amplifiersFeedback amplifiers
Feedback amplifiers
 
Compile time polymorphism
Compile time polymorphismCompile time polymorphism
Compile time polymorphism
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Presentation on graphs
Presentation on graphsPresentation on graphs
Presentation on graphs
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

Oo ps

  • 1.
  • 2. Object-oriented programming (OOP) is a programming paradigm using “objects”  An object is an identifiable entity with some characteristics and behaviour.  Very different approach than function-based programming (like C).
  • 3.
  • 4.  A class definition begins with the keyword class.  The body of the class is contained within a set of braces, { } ; (notice the semi-colon). class class_name Any valid } identifier .… .… Class body (data member .… + methods) methods ;{
  • 5. Within the body, the keywords private: and public: specify the access level of the members of the class. ◦ the default is private.  Usually, the data members of a class are declared in the private: section of the class and the member functions are in public: section.
  • 6. class class_name } :private … private members or … methods … public: … … Public members or methods … ;{
  • 7. Member access specifiers ◦ public:  can be accessed outside the class directly.  The public stuff is the interface. ◦ private:  Accessible only to member functions of class  Private members and methods are for internal use only.
  • 8. This class example shows how we can encapsulate (gather) a circle information into one package (unit or class) No need for others classes to class Circle access and retrieve its value directly. The { class methods are responsible for private: that only. double radius; public: void setRadius(double r); They are accessible from outside double getDiameter(); the class, and they can access the double getArea(); member (radius) double getCircumference(); };
  • 9. Declaring a variable of a class type creates an object. You can have many variables of the same type (class). ◦ Instantiation  Once an object of a certain class is instantiated, a new memory location is created for it to store its data members and code  You can instantiate many objects from a class type. ◦ Ex) Circle c; Circle *c;
  • 10. Constructor: ◦ Public function member. ◦ Called when a new object is created (instantiated). ◦ Initialize data members. ◦ Same name as class. ◦ No return type. ◦ They can be overloaded.
  • 11. class Circle Constructor with no { argument private: double radius; public: Constructor with one Circle(); argument Circle(int r); void setRadius(double r); double getDiameter(); double getArea(); double getCircumference(); };
  • 12.  Class implementation: writing the code of class methods.  There are two ways: ◦ Member functions defined outside class  Using Binary scope resolution operator (::)  “Ties” member name to class name  Uniquely identify functions of particular class  Different classes can have member functions with same name ◦ Format for defining member functions  ReturnType ClassName::MemberFunctionName( )  {  …  }
  • 13. 2. Member functions defined inside class ◦ Do not need scope resolution operator, class name; class Circle { Defined private: inside double radius; class public: Circle() { radius = 0.0;} Circle(int r); void setRadius(double r){radius = r;} double getDiameter(){ return radius *2;} double getArea(); double getCircumference(); };
  • 14. class Circle { private: double radius; public: Circle() { radius = 0.0;} Circle(int r); void setRadius(double r){radius = r;} double getDiameter(){ return radius *2;} double getArea(); double getCircumference(); }; Circle::Circle(int r) { Defined outside class radius = r; } double Circle::getArea() { return radius * radius * (22.0/7); } double Circle:: getCircumference() { return 2 * radius * (22.0/7); }
  • 15. Operators to access class members ◦ Identical to those for struct ◦ Dot member selection operator (.)  Object  Reference to object ◦ Arrow member selection operator (->)  Pointers
  • 16. class Circle { private: double radius; public: The first constructor Circle() { radius = 0.0;} // DC being called and the Circle(int r); // Parameterised constructure second parameterised constructor is called void setRadius(double r){radius = r;} after that. double getDiameter(){ return radius *2;} double getArea(); double getCircumference(); void main() Since radius is a }; { private class Circle::Circle(int r) Circle c1,c2(7); data member { radius = r; cout<<“The area of c1:” <<c1.getArea()<<“n”; } double Circle::getArea() //c1.radius= 5;//syntax error { c1.setRadius(5); return radius * radius * (22.0/7); } cout<<“The circumference of c1:” double Circle:: getCircumference() << c1.getCircumference()<<“n”; { return 2 * radius * (22.0/7); cout<<“The Diameter of c2:” <<c2.getDiameter()<<“n”; } }
  • 17. class Circle { private: double radius; public: Circle() { radius = 0.0;} Circle(int r); void setRadius(double r){radius = r;} double getDiameter(){ return radius *2;} double getArea(); double getCircumference(); }; Circle::Circle(int r) void main() { { Circle c(7); radius = r; Circle *cp1 = &c; } Circle *cp2 = new Circle(7); double Circle::getArea() { cout<<“The are of cp2:” return radius * radius * (22.0/7); <<cp2->getArea(); } double Circle:: getCircumference() } { return 2 * radius * (22.0/7); }
  • 18. Destructors ◦ Special member function ◦ Same name as class  Preceded with tilde (~) ◦ No arguments ◦ No return value ◦ Cannot be overloaded ◦ Before system reclaims object’s memory  Reuse memory for new objects  Mainly used to de-allocate dynamic memory locations
  • 19. 1. Simplifies programming 2. Interfaces  Information hiding: Implementation details hidden within classes themselves 1. Software reuseability  Class objects included as members of other classes