SlideShare a Scribd company logo
OOPs with C++ Lecture 4
What is Object Oriented Programming? An object is like a black box. The internal details are hidden. Identifying  objects  and assigning  responsibilities  to these objects. Objects communicate to other objects by sending  messages . Messages are received by the  methods  of an object
The two steps of Object Oriented Programming Making Classes:   Creating, extending or reusing abstract data types. Making Objects interact:   Creating objects from abstract data types and defining their relationships.
Example: The Creature class class Creature {  private: int yearOfBirth; public:  void setYearOfBirth(year) { yearOfBirth = year; } int getYearOfBirth() {  return yearOfBirth; }  };
Example: The Creature class class Creature {  private: int yearOfBirth; public:  void setYearOfBirth(year); int getYearOfBirth(); }; void Creature::setYearOfBirth { yearOfBirth = year; } int Creature::getYearOfBirth() {  return yearOfBirth; }  Note that unless the methods are very short, declaration and implementation is usually separated. The declaration goes into a header file (.h), the implementation in a .cpp file.
Classes & Objects What may be different for all objects in a class, and what remains the same? All the objects in a class may have different attribute values (state data), but their allowed behaviours are all the same. So a class is a blueprint for objects
Objects & Classes A class is defined by: A Unique Name Attributes Methods An object is defined by: Identity State Behaviour
Instantiating Objects An object is instantiated just like any other data type: int x; char y; Creature z;   Declaring z of type ‘creature’  means we have generated an object with the attributes and methods of the class.
Multiple Objects Of course we can create many objects of the same class: Creature myDog; Creature theMilkman; Creature myBestFriend; Creates three objects.
Sending Messages /    Calling Methods. A message is send to an object by calling a method of this object. Use the . (dot) for calling a method of an object. int k;  k =  theMilkman.getYearOfBirth(); myDog.setYearOfBirth(1998); Messages are sent to my dog and the milkman.
Back to the Instantiation... An object is instantiated just like any other data type: int x; char y; Creature z;   Here the “default constructor” of the Creature class is automatically called. If we don’t like this we can specify constructors explicitly!
End

More Related Content

PPT
Lecture 2
PPT
PPTX
Object Oriented Concept
PPTX
Object oriented programming concepts
PDF
4 pillars of OOPS CONCEPT
PPTX
Object Oriented Programming Concepts
PPT
What is OOP?
Lecture 2
Object Oriented Concept
Object oriented programming concepts
4 pillars of OOPS CONCEPT
Object Oriented Programming Concepts
What is OOP?

What's hot (20)

PPTX
Oops concept in c++ unit 3 -topic 4
PPT
C plusplus
PPTX
Oo ps concepts in c++
PPT
Oops And C++ Fundamentals
PPTX
concept of oops
PPT
Object Oriented Programming Concepts
PPT
General OOP concept [by-Digvijay]
PPTX
Std 12 computer chapter 6 object oriented concepts (part 1)
PDF
Object oriented concepts
PPT
Object Oriented Language
PDF
Object Oriented Concepts in Real Projects
PPTX
Introduction to Object Oriented Programming
PPTX
Characteristics of oop
PPT
Object Oriented Programming Concepts using Java
PPTX
Object oriented programming concept
PPTX
Object Oriented Technologies
PDF
Oop concepts classes_objects
PPTX
Oop ppt
PPTX
object oriented programing lecture 1
PPT
Object Oriented Concepts and Principles
Oops concept in c++ unit 3 -topic 4
C plusplus
Oo ps concepts in c++
Oops And C++ Fundamentals
concept of oops
Object Oriented Programming Concepts
General OOP concept [by-Digvijay]
Std 12 computer chapter 6 object oriented concepts (part 1)
Object oriented concepts
Object Oriented Language
Object Oriented Concepts in Real Projects
Introduction to Object Oriented Programming
Characteristics of oop
Object Oriented Programming Concepts using Java
Object oriented programming concept
Object Oriented Technologies
Oop concepts classes_objects
Oop ppt
object oriented programing lecture 1
Object Oriented Concepts and Principles
Ad

Viewers also liked (20)

DOC
Assignment#4 gorosito
PPS
I love you
DOC
Hepatitis a
DOC
Sensatez...
DOC
O jornal...
PDF
BCI Softline Library Seating Catalog (2011)
DOCX
Autobiografia cleo
PPT
Euthenics How to dress on a date Powerpoint
DOCX
Formas basicas con sombra (1)
PDF
Membership Crossroads
PPTX
Schools direct pres_updated[1]
PPTX
Empirical investment group
PPT
Thankful Memes
PPTX
El pueblo quezon city
XLSX
เสาวลักษณ์
PPTX
Pest(tech)
PPT
Thankful Memes Updated
DOC
Essay final exam - marina gorosito
PDF
Euro shop 2014 trend recap
Assignment#4 gorosito
I love you
Hepatitis a
Sensatez...
O jornal...
BCI Softline Library Seating Catalog (2011)
Autobiografia cleo
Euthenics How to dress on a date Powerpoint
Formas basicas con sombra (1)
Membership Crossroads
Schools direct pres_updated[1]
Empirical investment group
Thankful Memes
El pueblo quezon city
เสาวลักษณ์
Pest(tech)
Thankful Memes Updated
Essay final exam - marina gorosito
Euro shop 2014 trend recap
Ad

Similar to Lecture 4 (20)

PPT
香港六合彩 » SlideShare
PPTX
Basic concept of oops
PPTX
Chapter2 array of objects
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
PDF
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
PDF
C++ largest no between three nos
PDF
Basic OOPs Concepts (E-next.in).pdf
PPTX
Java PPT OOPS prepared by Abhinav J.pptx
PPT
Objects by Sufian Idris
PDF
Python Programming - Object-Oriented
PPT
PDF
Assignment #4 will be the construction of 2 new classes and a driver program/...
PPT
how to create object
PPTX
Classes-and-Object.pptx
PPTX
CSharp_03_Inheritance_introduction_with_examples
PPTX
Object Oriented Programming using C++(UNIT 1)
PPTX
software construction and development week 3 Python lists, tuples, dictionari...
PDF
Object Oriented PHP - PART-1
香港六合彩 » SlideShare
Basic concept of oops
Chapter2 array of objects
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
C++ largest no between three nos
Basic OOPs Concepts (E-next.in).pdf
Java PPT OOPS prepared by Abhinav J.pptx
Objects by Sufian Idris
Python Programming - Object-Oriented
Assignment #4 will be the construction of 2 new classes and a driver program/...
how to create object
Classes-and-Object.pptx
CSharp_03_Inheritance_introduction_with_examples
Object Oriented Programming using C++(UNIT 1)
software construction and development week 3 Python lists, tuples, dictionari...
Object Oriented PHP - PART-1

More from emailharmeet (19)

PPT
Lecture 10 distributed database management system
PPT
Lecture 09 dblc centralized vs decentralized design
PPT
Lecture 09 dblc centralized vs decentralized design
PPT
Lecture 08 distributed dbms
PPT
Lecture 07 relational database management system
PPT
Lecture 06 relational algebra and calculus
PPTX
Testing lecture after lec 4
PPT
PPTX
Revision Lecture
PPT
Lecture 3 c++
DOCX
Course File c++
PPT
Lecture 05 dblc
DOCX
Assignmnet 1
PPT
Lecture 04 normalization
PPT
Lecture 03 data abstraction and er model
PPT
Lecture 02 terminology of database
PPT
Lecture 01 introduction to database
PPT
Lecture 00 introduction to course
DOC
Syllabus mca 2 rdbms i
Lecture 10 distributed database management system
Lecture 09 dblc centralized vs decentralized design
Lecture 09 dblc centralized vs decentralized design
Lecture 08 distributed dbms
Lecture 07 relational database management system
Lecture 06 relational algebra and calculus
Testing lecture after lec 4
Revision Lecture
Lecture 3 c++
Course File c++
Lecture 05 dblc
Assignmnet 1
Lecture 04 normalization
Lecture 03 data abstraction and er model
Lecture 02 terminology of database
Lecture 01 introduction to database
Lecture 00 introduction to course
Syllabus mca 2 rdbms i

Lecture 4

  • 1. OOPs with C++ Lecture 4
  • 2. What is Object Oriented Programming? An object is like a black box. The internal details are hidden. Identifying objects and assigning responsibilities to these objects. Objects communicate to other objects by sending messages . Messages are received by the methods of an object
  • 3. The two steps of Object Oriented Programming Making Classes: Creating, extending or reusing abstract data types. Making Objects interact: Creating objects from abstract data types and defining their relationships.
  • 4. Example: The Creature class class Creature { private: int yearOfBirth; public: void setYearOfBirth(year) { yearOfBirth = year; } int getYearOfBirth() { return yearOfBirth; } };
  • 5. Example: The Creature class class Creature { private: int yearOfBirth; public: void setYearOfBirth(year); int getYearOfBirth(); }; void Creature::setYearOfBirth { yearOfBirth = year; } int Creature::getYearOfBirth() { return yearOfBirth; } Note that unless the methods are very short, declaration and implementation is usually separated. The declaration goes into a header file (.h), the implementation in a .cpp file.
  • 6. Classes & Objects What may be different for all objects in a class, and what remains the same? All the objects in a class may have different attribute values (state data), but their allowed behaviours are all the same. So a class is a blueprint for objects
  • 7. Objects & Classes A class is defined by: A Unique Name Attributes Methods An object is defined by: Identity State Behaviour
  • 8. Instantiating Objects An object is instantiated just like any other data type: int x; char y; Creature z; Declaring z of type ‘creature’ means we have generated an object with the attributes and methods of the class.
  • 9. Multiple Objects Of course we can create many objects of the same class: Creature myDog; Creature theMilkman; Creature myBestFriend; Creates three objects.
  • 10. Sending Messages / Calling Methods. A message is send to an object by calling a method of this object. Use the . (dot) for calling a method of an object. int k; k = theMilkman.getYearOfBirth(); myDog.setYearOfBirth(1998); Messages are sent to my dog and the milkman.
  • 11. Back to the Instantiation... An object is instantiated just like any other data type: int x; char y; Creature z; Here the “default constructor” of the Creature class is automatically called. If we don’t like this we can specify constructors explicitly!
  • 12. End