0% found this document useful (0 votes)
73 views15 pages

Class & Objects: Presented By:-Akshat Gupta BCA209 35225502019

This document provides an introduction to classes and objects in C++. It defines a class as a blueprint for creating objects with common properties and methods. The key points covered include: - Classes allow data and functions to be grouped together to represent real-world entities. - A class definition specifies the data members and member functions using access specifiers like public and private. - Objects are instances of a class that allocate memory dynamically. They can access class data members and call member functions. - Access specifiers determine whether class members can be accessed from within or outside the class. Public members can be accessed anywhere while private members can only be accessed within the class. - An example class called math

Uploaded by

jims bca2019
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)
73 views15 pages

Class & Objects: Presented By:-Akshat Gupta BCA209 35225502019

This document provides an introduction to classes and objects in C++. It defines a class as a blueprint for creating objects with common properties and methods. The key points covered include: - Classes allow data and functions to be grouped together to represent real-world entities. - A class definition specifies the data members and member functions using access specifiers like public and private. - Objects are instances of a class that allocate memory dynamically. They can access class data members and call member functions. - Access specifiers determine whether class members can be accessed from within or outside the class. Public members can be accessed anywhere while private members can only be accessed within the class. - An example class called math

Uploaded by

jims bca2019
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/ 15

CLASS & OBJECTS

Presented By:-
AKSHAT GUPTA
BCA209
35225502019
An Introduction To Classes
 A class is a building block of OOP. It is the
way to bind the data and its logically related
functions together.
 An abstract data type that can be treated
like any other built in data type.
Class Definition
 Class head class name_of_class.
 Class body {

};
Class Syntax
class classname{
Access specifier :
Member variable Declaration;
Member Function Declaration;
};
#include<iostream>
Example using namespace std;
class maths{
int x,y;
public:
void input() //creating a member function to take
input from the user
{
cout<<"Enter two integers : \n";
cin>>x>>y;
}
void add() //creating a member function to perform
addition of the entered no.
{
cout<<"Result : "<<x+y;
}
};
Access Specifiers & Its Types
Access specifiers define how the members
(attributes & methods) of a class can be accessed.
In C++ there are three types of access specifiers:-
1.Public.
2.Private.
3.Protected.
Access Specifiers & Its Types(Contd.)

1.Public : - It is the first type of access specifiers


in C++, which allows the members of the class
to be accessed from outside the class.
Example: class m{//the class
public: // access specifier
//class members };
Access Specifiers & Its Types(Contd.)

2.Private : - The second type of the access


specifier in C++ is Private. In this the members
cannot be accessed (or viewed) from outside the
class.
Example: class m{//the class
private: // access specifier
//class members };
Access Specifiers & Its Types(Contd.)

3.Protected : - The third & last access specifier in C+


+ is Protected. It does not allows the members to be
accessed from outside the class, however,
they can be accessed in inherited classes.
Example: class m{//the class
protected: // access specifier
//class members };
Member Function and Its Features
Member function of a class is a function that has its
definition or its prototype within the class definition
like any other variable.
Features : -
1. Member function’s name is visible outside the
class.
2. It can be defined inside or outside the class.
3. It can have access to private, public and
protected data members of its class, but cannot
access private data members of another class.
Introduction To Objects
Object is an abstraction of real world entity. It is also
known as the variables / instances of classes.
Syntax for declaring objects is as follows :
<class name>
<obj_name1>,<obj_name2>, …, <obj_name1>;

Example: class c{//it is class named as c};


int main(){c t1,t2,…tn;//objects created for
the class }
Features Of Objects
1.It can have its own copy of data members.
2. The scope of an object is determined by the place
in which the object is defined.
3.It can be passed to a function like normal
variables.
4. The members of the class can be accessed by
the object using the object to member access
operator or dot operator(.).
Example int main()
{
#include<iostream> maths m;//creating an object of
using namespace std; the class
class maths{ m.input();//calling the function
int x,y; input using object m
public: m.add();//calling the function
void input() //creating a member function to add using object m
take input from the user return 0;
{cout<<"Enter two integers : \n“;
}
cin>>x>>y; }
void add() //creating a member function to
Output:
perform addition of the entered no. and print
Enter two integers :
the output
2
{
5
cout<<"Result : "<<x+y;
Result :7
}
};
REFERENCES

https://www.geeksforgeeks.org/c-classes-and-objects/

https://www.w3schools.com/cpp/cpp_classes.asp

https://www.slideshare.net/PayelGuria/class-and-objects
THANK YOU!

You might also like