Class and Object in C++ |C++ learn- Basic IT Topic

Class and Object in C++

Class:-

The major destinations of Class and object in c++ are given below:-

The class is used to create the blueprint or architecture. Class is the combination of data member and member function.Class is a user-defined data type, which holds its own data members and member functions or method, which can be accessed and used by creating an instance or object of that class.

For Example:- Consider the class of College. There may be many different types of college present with the different name but all of them will provide a common property like study, library, id card.o here College is the class and study, library, id card are their properties.

Object:-

An Object is an instance of a class. Object allocates memory but class does not allocate memory.

Defining the class:-

A class is defined in C++ using class keyword and followed by the name of the class. The body of the class is defined inside the bracket and terminated by a semicolon at the end.

Class and object in c++

Declaring Object:-

To use the data and access the function we need to declare the object.

Syntax:

ClassName ObjectName;

What is the difference between method inside class and method outside class?

Method can be defined inside the class and outside the class.

Method defined inside the call are by default inline, but method outside the class are not by default inline.

To define the method outside the class:

  • first, define the prototype inside the class.
  • second, define the method outside the class using class name and using scope resolution operator(::)

 

basicittopic

basicittopic

A Computer Science Study for IT students and people of IT community