0% found this document useful (0 votes)
20 views

Class and Object

Object oriented programs about classes and object oriented
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Class and Object

Object oriented programs about classes and object oriented
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

There are many differences between object and class. Some differences
between object and class are given below:
Class Object

Class is used as a template for declaring


and An object is an instance of a class.
creating the objects.

When a class is created, no memory is Objects are allocated memory space


allocated. whenever they are created.

The class has to be declared first and An object is created many times as per
only once. requirement.

A class can not be manipulated as they


are not Objects can be manipulated.
available in the memory.

A class is a logical entity. An object is a physical entity.

It is created with a class name in C++


It is declared with the class keyword and
with the new keywords in Java.

Each object has its own values, which


Class does not contain any values which
are
can be associated with the field.
associated with it.

A class is used to bind data as well as


Objects are like a variable of the class.
methods together as a single unit.

Syntax: Declaring Class in C++ is as Syntax: Instantiating an object for a


follows: Class in C++ is as follows:
class <classname> {}; class Student {
public:
void put(){
Class Object

cout<<“Function Called”<<endl;
}
}; // The class is declared here
int main(){
Student s1; // Object created
s1.put();
}

Example: Bike Example: Ducati, Suzuki, Kawasaki

You might also like