Beruflich Dokumente
Kultur Dokumente
CLASSES AND
OBJECTS
Class
Object
Instantiation of a class.
In terms of variables, class would be the
type and an object would be a variable.
Classes in C++
Any valid
identifier
Class body (data
member + methods)
class classname
{
private:
variable declarations;
function declarations;
public:
variable declarations;
function declarations;
protected:
variable declarations;
function declarations;
} obj1, obj2,..objN;
Class name
Data Members
Member functions
Access Specifiers
Classes in C++
class class_name
{
private:
public:
};
private members or
methods
Public members or
methods
Private:
only members of that class have
accessibility
can be accessed only through member
functions of that class.
Private
Public:
Accessible from outside the class
can be accessed through member
function of any class in the same
program.
Protected:
Stage between private and public
access.
They cannot be accessed from outside
the class, but can be accessed from the
derived class.(inheritance)
Class Example
public
private
protected
Declaring objects:
A class declaration only uses to build the
structure of an object.
Declaration of an object is same as
declaration of class.
Defining objects of class data type is known
as class instantiation(instances of class)
When we create objects during that
moment , memory is allocated to them.
Ex- Circle c;
class Customer
{
void accept()
{
cout << Accepting Customer Details << endl;
}
void display()
{
cout << Displaying Customer Details << endl;
}
};
Void main()
{
Customer C1;
C1.accept();
C1.display();
getch();