0% found this document useful (0 votes)
20 views6 pages

OOP Lecture 4

The document discusses object-oriented programming concepts like class, object, data members, member functions, access specifiers, and how to define a class and create objects in C++. It provides details on how classes are used to create user-defined data types and access data members and functions through objects.

Uploaded by

ayesha sabir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views6 pages

OOP Lecture 4

The document discusses object-oriented programming concepts like class, object, data members, member functions, access specifiers, and how to define a class and create objects in C++. It provides details on how classes are used to create user-defined data types and access data members and functions through objects.

Uploaded by

ayesha sabir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

OBJECT-ORIENTED Lecture 4

PARADIGM Instructor : Syeda Hira Fatima


CLASS
a class is a blueprint for creating objects (a particular data structure), providing
initial values for state (member variables or attributes), and implementations of
behavior (member functions or methods).
It is a user-defined data type, which holds its own data members and member
functions, which can be accessed and used by creating an instance of that class.
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 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.
Defining Class and Declaring Object
A class is defined in C++ using the keyword class followed by the name of the class.
The body of the class is defined inside the curly brackets and terminated by a
semicolon at the end.
Declaring Objects
When a class is defined, only the specification for the object is defined; no memory or storage is
allocated. To use the data and access functions defined in the class, you need to create objects.
Syntax:
Class Name Object Name;
Accessing Data Members
The public data members are also accessed in the same way given however the private data
members are not allowed to be accessed directly by the object. Accessing a data member
depends solely on the access control of that data member.
There are three access modifiers: public, private, and protected.
#include <bits/stdc++.h>
using namespace std;
Class Human {
// Access specifier
public:
// Data Members
string name;
// Member Functions()
void printname() { cout << “Name is:" <<name; }
};
int main()
{
// Declare an object of class geeks
Human obj1;
// accessing data member
obj1.name = "Abhi";
// accessing member function
obj1.printname();
return 0;
}

You might also like