Professional Documents
Culture Documents
Chapter Six
Chapter Six
Object-Oriented Programming
Object Oriented Programming in C++ - GeeksforGeeks
Outlines
Introduction
Basic components of oop
Principles of oop
Introduction
Object-oriented programming aims to implement real-world entities like inheritance,
hiding, polymorphism, etc. in programming.
The main aim of OOP is to bind together the data and the functions that operate on
them so that no other part of the code can access this data except that function.
Object-oriented programming is about creating objects that contain both data and
functions
Procedural programming is about writing procedures or functions that perform
operations on the data
Advantages of Object-oriented programming (OOP):
OOP is faster and easier to execute
OOP provides a clear structure for the programs
OOP helps to keep the code “Don't Repeat Yourself”
OOP makes the code easier to maintain, modify and debug
OOP create full reusable applications with less code and shorter development
time
• There are some basic concepts that act as the building blocks of OOPs
i.e.
1.Class
2.Objects
3.Encapsulation
4.Abstraction
5.Polymorphism
6.Inheritance
-
Class and Object
• A Class is a user-defined data type that has data members and member functions.
• A class is a collection of a fixed number of components.
• Data members are the data variables and member functions are the functions
used to manipulate these variables together these data members and member
functions define the properties and behavior of the objects in a Class.
• Object
• An Object is an identifiable entity with some characteristics and behavior. An
Object is an instance of a Class. When a class is defined, no memory is allocated
but when it is instantiated (i.e. an object is created) memory is allocated.
• Class is a set of similar objects
• Class is a blueprint to create objects of that class.
• Class is defined with Class keyword
• Object is an instance of a class
The general syntax for defining a class is:
class classIdentifier { classMembersList };
Example, consider a class called Student has student objects
student object has attributes like
ID
Name
Gender
GPA
student object has behaviors like
Register()
viewGrade ()
AddCourse ()
DropCourse ()
Withdraw ()
Access specifiers