SlideShare a Scribd company logo
Lecture 02



Fundamentals
      of
Object-Oriented
Programming
What Are Objects?

Software objects model real-world objects or abstract concepts.
     dog, bicycle, queue

Real-world objects have states and behaviors.
      Dogs' states: name, color, breed, hungry
      Dogs' behaviors: barking, fetching

How do software objects implement real-world objects?
     Use variables/data to implement states.
     Use methods/functions to implement behaviors.

An object is a software bundle of variables and related methods.
Software Object
        Visual Representation


Instance Variables Vs Instance Methods
Software Bicycle
Visual Representation
What Are Classes?


• A class is a blueprint or prototype defining the
  variables and methods common to all objects of
  a certain kind.

• An object is an instance of a certain class.

• After you have created a class, you must create
  an instance of it before you can use.

• Class variables and class methods.
What Are Messages?




Software objects interact and communicate with
each other by sending messages to each other.
Components Of A Message




 The object to whom the message is addressed
(YourBicycle)
The name of the method to perform (changeGears)
Any parameters needed by the method (lowerGear)
O-O Principles

• Abstraction - take only important
  information
• Encapsulation - hiding or combine data
  and operations on data in a single unit.
• Inheritance - create new objects from
  existing objects.
• Polymorphism-the ability to use the same
  expression to denote different operations.
Encapsulation

• The objects' variables make up the center of
  the object.

• Methods surround and hide the object's
  center from other objects.

• Benefit of encapsulation: Modularity &
  Information Hiding.

• For implementation or efficiency reasons, an
  object may wish to expose some of its
  variables or hide some of its methods.
Inheritance

• Inheritance allows classes to be defined in terms of
  other classes.

• Each subclass inherits variables and methods from its
  superclass.

• Subclasses can add variables and methods to the
  ones they inherit from the superclass.

• Subclasses can also override inherited methods and
  provide specialized implementations for those
  methods.
Class Hierarchy
             (Inheritance Hierarchy)




Superclass vs Subclass.
Base Class vs Derived Class.
Polymorphism and Overloading

• Polymorphism allows the use of operators or functions
  in different ways, depending on the data they are
  operating on.

• When an existing operator (eg. + or =) is given the
  capability to operate on a new data type, it is said to
  be overloaded.

• Overloading is a kind of polymorphism; it is also an
  important feature of OOP.
• Example of operator overloading and polymorphism)
• the + operator know how to treat an integer and a float
  differently.
Benefits of OOP
                       Reusability

• Once written, created, and debugged, a class can be
  distributed to other programmers for use in their own
  programs.

• Reusability facilitates component-based software
  design and implementation.

• A programmer can also take an existing class and,
  without modifying it, add additional features and
  capabilities to it.
Benefits of OOP
               Creating New Data Types

• Objects and classes give the programmer a
  convenient way to construct new data types.

• Many features of C++ are intended to facilitate the
  creation of new data types.

• The ability to create new data types leads to
  extensible languages and programs.

• In C++, new data types can be built on top of existing
  (system or user-defined) data types.
C++ Program Structure

                           #include <iostream.h>
Header files
preprocessor statements
class      Data            int main( )    // VOID
           Members
{ …..
           and Member      {
}          Functions
main( )   Variable
                           cout << “Welcome to C++”;
{ ……      declarations &   return 0;
          valid C++
}         statements
                           }
Example 2

#include <iostream.h>                Sum = a + b + c;
int main ( )                         cout << “ the sum is “<< sum;
{ int a , b, c, sum =0;
  cout << “ enter a value “<<endl;      OTHER DATA TYPES
  cin >> a;                                   Char
                                                int
  cout << “ enter b value “<<endl;           long int
                                               float
  cin >> b;
                                              double
  cout << “ enter c value “<<endl;
  cin >> c;
Input / Output

Cout - used for printing out the output
Syntax :
      Cout << “Message if needed”<< variablename;
      << is called the insertion operator.
Cin - used for getting a input from the keyboard
Syntax:
      Cin >> variable name;
      >> is called the extraction operator
Other Points

Remark statement - it is a non executable statement
                      used for documentation
                    //       or   /* statements */
escape sequences:
      n - new line
      t - horizontal tab
      r - carriage return
      a - bell
       - back slash ” - double quotations
Lecture02
Lecture02
Lecture02
Lecture02

More Related Content

PDF
Object Oriented Programming Concepts
PPTX
OOPS features using Objective C
PPT
C++ classes
PPTX
class and objects
PPTX
Constructor and Destructors in C++
PPTX
PPTX
OOPS Basics With Example
Object Oriented Programming Concepts
OOPS features using Objective C
C++ classes
class and objects
Constructor and Destructors in C++
OOPS Basics With Example

What's hot (20)

PPTX
C++ programming introduction
PPTX
Constructor in java
PPT
Polymorphism
PPTX
pointers,virtual functions and polymorphism
PDF
Chapter27 polymorphism-virtual-function-abstract-class
PPTX
Objective c slide I
PPTX
Polymorphism in c++(ppt)
PPTX
Python - OOP Programming
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPT
Java oops PPT
PDF
Constructors destructors
PDF
Inheritance
PDF
Constructors and destructors
PDF
Object Oriented Programming using C++ Part I
PPTX
Static Data Members and Member Functions
PPTX
iOS Basic
PPT
Inheritance : Extending Classes
PPT
106da session5 c++
PPTX
Python oop class 1
PPT
Basic c#
C++ programming introduction
Constructor in java
Polymorphism
pointers,virtual functions and polymorphism
Chapter27 polymorphism-virtual-function-abstract-class
Objective c slide I
Polymorphism in c++(ppt)
Python - OOP Programming
Basic Concepts of OOPs (Object Oriented Programming in Java)
Java oops PPT
Constructors destructors
Inheritance
Constructors and destructors
Object Oriented Programming using C++ Part I
Static Data Members and Member Functions
iOS Basic
Inheritance : Extending Classes
106da session5 c++
Python oop class 1
Basic c#
Ad

Viewers also liked (10)

PPT
Fundamentals of oop lecture 2
PDF
ITFT - Oops
PDF
Oop.concepts
PDF
12 object oriented programming
DOC
Question bank unit i
PPT
7. Multithreading
PPTX
Module1 elementary concepts of objects and classes
PPT
6. Exception Handling
PDF
A COMPLETE FILE FOR C++
Fundamentals of oop lecture 2
ITFT - Oops
Oop.concepts
12 object oriented programming
Question bank unit i
7. Multithreading
Module1 elementary concepts of objects and classes
6. Exception Handling
A COMPLETE FILE FOR C++
Ad

Similar to Lecture02 (20)

PPTX
C++ & Data Structure - Unit - first.pptx
PPTX
Programming Language
PDF
C++ Interview Questions and Answers PDF By ScholarHat
PPTX
Introduction to C++
PPTX
Object oriented programming. (1).pptx
PPTX
OOC MODULE1.pptx
PPTX
Presentation on topic of c and c++ programming language.(.pptx
PPTX
Nitin Mishra 0301EC201039 Internship PPT.pptx
PPTX
Introduction Of C++
PPTX
C++ Intro C++ Intro C++ Intro C++ Intro C++ Intro
PPTX
Presentation 4th
PPT
Objective-C for iOS Application Development
PPTX
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
PPTX
Introduction to c_plus_plus (6)
PPTX
Introduction to c_plus_plus
PPSX
SRAVANByCPP
PDF
OOP UNIT 1_removed ppt explaining object.pdf
PPTX
OOP CHAPTER object oreinted programming using c++
PPTX
Presentation 3rd
C++ & Data Structure - Unit - first.pptx
Programming Language
C++ Interview Questions and Answers PDF By ScholarHat
Introduction to C++
Object oriented programming. (1).pptx
OOC MODULE1.pptx
Presentation on topic of c and c++ programming language.(.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
Introduction Of C++
C++ Intro C++ Intro C++ Intro C++ Intro C++ Intro
Presentation 4th
Objective-C for iOS Application Development
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
Introduction to c_plus_plus (6)
Introduction to c_plus_plus
SRAVANByCPP
OOP UNIT 1_removed ppt explaining object.pdf
OOP CHAPTER object oreinted programming using c++
Presentation 3rd

More from elearning_portal (14)

PPT
Lecture05
PPT
Lecture21
PPT
Lecture19
PPT
Lecture18
PPT
Lecture17
PPT
Lecture16
PPT
Lecture10
PPT
Lecture09
PPT
Lecture07
PPT
Lecture06
PPT
Lecture20
PPT
Lecture03
PPT
Lecture01
PPT
Lecture04
Lecture05
Lecture21
Lecture19
Lecture18
Lecture17
Lecture16
Lecture10
Lecture09
Lecture07
Lecture06
Lecture20
Lecture03
Lecture01
Lecture04

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
master seminar digital applications in india
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
01-Introduction-to-Information-Management.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Classroom Observation Tools for Teachers
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Sports Quiz easy sports quiz sports quiz
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
master seminar digital applications in india
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
01-Introduction-to-Information-Management.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Complications of Minimal Access Surgery at WLH
Classroom Observation Tools for Teachers
O5-L3 Freight Transport Ops (International) V1.pdf
Insiders guide to clinical Medicine.pdf
PPH.pptx obstetrics and gynecology in nursing
Sports Quiz easy sports quiz sports quiz
2.FourierTransform-ShortQuestionswithAnswers.pdf
TR - Agricultural Crops Production NC III.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Supply Chain Operations Speaking Notes -ICLT Program
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
STATICS OF THE RIGID BODIES Hibbelers.pdf

Lecture02

  • 1. Lecture 02 Fundamentals of Object-Oriented Programming
  • 2. What Are Objects? Software objects model real-world objects or abstract concepts. dog, bicycle, queue Real-world objects have states and behaviors. Dogs' states: name, color, breed, hungry Dogs' behaviors: barking, fetching How do software objects implement real-world objects? Use variables/data to implement states. Use methods/functions to implement behaviors. An object is a software bundle of variables and related methods.
  • 3. Software Object Visual Representation Instance Variables Vs Instance Methods
  • 5. What Are Classes? • A class is a blueprint or prototype defining the variables and methods common to all objects of a certain kind. • An object is an instance of a certain class. • After you have created a class, you must create an instance of it before you can use. • Class variables and class methods.
  • 6. What Are Messages? Software objects interact and communicate with each other by sending messages to each other.
  • 7. Components Of A Message The object to whom the message is addressed (YourBicycle) The name of the method to perform (changeGears) Any parameters needed by the method (lowerGear)
  • 8. O-O Principles • Abstraction - take only important information • Encapsulation - hiding or combine data and operations on data in a single unit. • Inheritance - create new objects from existing objects. • Polymorphism-the ability to use the same expression to denote different operations.
  • 9. Encapsulation • The objects' variables make up the center of the object. • Methods surround and hide the object's center from other objects. • Benefit of encapsulation: Modularity & Information Hiding. • For implementation or efficiency reasons, an object may wish to expose some of its variables or hide some of its methods.
  • 10. Inheritance • Inheritance allows classes to be defined in terms of other classes. • Each subclass inherits variables and methods from its superclass. • Subclasses can add variables and methods to the ones they inherit from the superclass. • Subclasses can also override inherited methods and provide specialized implementations for those methods.
  • 11. Class Hierarchy (Inheritance Hierarchy) Superclass vs Subclass. Base Class vs Derived Class.
  • 12. Polymorphism and Overloading • Polymorphism allows the use of operators or functions in different ways, depending on the data they are operating on. • When an existing operator (eg. + or =) is given the capability to operate on a new data type, it is said to be overloaded. • Overloading is a kind of polymorphism; it is also an important feature of OOP. • Example of operator overloading and polymorphism) • the + operator know how to treat an integer and a float differently.
  • 13. Benefits of OOP Reusability • Once written, created, and debugged, a class can be distributed to other programmers for use in their own programs. • Reusability facilitates component-based software design and implementation. • A programmer can also take an existing class and, without modifying it, add additional features and capabilities to it.
  • 14. Benefits of OOP Creating New Data Types • Objects and classes give the programmer a convenient way to construct new data types. • Many features of C++ are intended to facilitate the creation of new data types. • The ability to create new data types leads to extensible languages and programs. • In C++, new data types can be built on top of existing (system or user-defined) data types.
  • 15. C++ Program Structure #include <iostream.h> Header files preprocessor statements class Data int main( ) // VOID Members { ….. and Member { } Functions main( ) Variable cout << “Welcome to C++”; { …… declarations & return 0; valid C++ } statements }
  • 16. Example 2 #include <iostream.h> Sum = a + b + c; int main ( ) cout << “ the sum is “<< sum; { int a , b, c, sum =0; cout << “ enter a value “<<endl; OTHER DATA TYPES cin >> a; Char int cout << “ enter b value “<<endl; long int float cin >> b; double cout << “ enter c value “<<endl; cin >> c;
  • 17. Input / Output Cout - used for printing out the output Syntax : Cout << “Message if needed”<< variablename; << is called the insertion operator. Cin - used for getting a input from the keyboard Syntax: Cin >> variable name; >> is called the extraction operator
  • 18. Other Points Remark statement - it is a non executable statement used for documentation // or /* statements */ escape sequences: n - new line t - horizontal tab r - carriage return a - bell - back slash ” - double quotations