Classes and Objects In C++

Classes and Objects In C++


Classes and Objects In C++ :

Classes :

The class definition is  starts with the keyword class followed by the class name and the class body.

Syntax :

class Box {

   public:

      double length;   // Length of a box

      double breadth;  // Breadth of a box

      double height;   // Height of a box

};

The keyword public Shows that the access attributes of the members of the class that follows it.

Classes and Objects In C++
Classes and Objects In C++



The public member can be accessed from outside the class anywhere within the scope of the class object.

And You can also specify the members of a class as private or protected which we will discuss in a sub-section.

May You Like To Read This Related Articles:

What Is Operating System? Knowledge Of OS!!

Operating System As A User Interface And As A Resource Manager - Technopedia!

Services Of Operating System - 
Technopedia!!!

Basic Concepts Of OOPC!!

CONCEPT OF DBMS!!

Types Of Operating System - Technopedia!!!

Basic Program Of C Language For Print Hello!!

Objects :

An object is the blueprints for objects, so basically an object is created from a class.

Here, are two objects of the class :



Box Box1;          // Declare Box1 of type Box

Box Box2;          // Declare Box2 of type Box



And Both of the objects Box1 and Box2 will have their own copy of data members.

Classes and Objects


Class is a user defined data type so, which holds its own data members and member functions, which can be accessed and used by creating instance of that class.

The variables inside class definition are the data members and the functions are member functions.

The Class name must start with an uppercase letter.

If class name is made of more than one word, then first letter of each word must be in uppercase.

Example : class Study, class Study Tonight etc..

So, Classes contain, data members and member functions, and the access of these data members and variable depends on the access specifiers.

The Class's member functions can be defined inside the class definition or outside the class definition.

So, Class in C++ are similar to structures in C, the only difference being, class defaults to private access control, where as structure defaults to public.

The All the features of OOPS, revolve around classes in C++. Inheritance, Encapsulation, Abstraction etc.

So, Objects of class holds separate copies of data members.

The Classes do posses more characteristics, like we can create abstract classes, immutable classes, all this we will study later.


Recommend Articles For More Information :

Introduction Of C++!!.

Operators In C++

Function Overloading In C++

Data Types in C++

Types Of Constructor In C++

Classes and Objects In C++

What Is Inheritance In C++?

Types Of Inheritance?

Basic Concepts Of OOPC!!

CONCEPT OF DBMS!!

Basic Program Of C Language For Print Hello!!

Objects of Classes


The Class is a blueprint or a template.

And No storage is assigned when we define a class.

The  Objects are instances of class, which holds the data variables declared in class and the member functions work on these class objects.

Each The object has different data variables.

The Objects are initialised using special class functions called Constructors.



class Abc

{

    int x;

    void display()

    {

        // some statement

    }

}; 



int main()

{

    Abc obj;   // Object of class Abc created

}

For More Knowledge Check This Articles For Better Understanding :

Machine Learning Technology in Software Engineering

Trending Pieces Of Technology You Should Know About!!!

CONCEPT OF DBMS!!

Phases Of Compiler In System Programming!!!!

C Program For Addition, Subtraction, Multiplication, Division Of Two Numbers!!

Difference between a monolithic and micro kernel?

Difference Between The Procedure Oriented Language and Object Oriented Language.

What Is Inheritance In C++? Types Of Inheritance?

Comments

Popular posts from this blog

What Is Inheritance In C++? Types Of Inheritance?

CONCEPT OF DBMS!!

Basic Concepts Of OOPC!!