C++ Object oriented programming Part-2

C++ Object oriented programming Part-2

  • Object means real word entity such as pen, chair, table etc
  • Any entity that has a state and behaviour is known as an object.
  • It can be physical and logical. 
  • Object is an instance of class. 
Example:-Car is an object. Its name is mercedes. Its colour is black etc known as its state. It is used for driving so driving is its behaviour. 

An object has three characteristics:

  • State:-Represent the data of an object
  • Behaviour:-Represent the functionality of an object. 
  • Identity :-object identity is typically implemented via unique ID. The value of the ID is not visible to external user. But it is used internally by  the JVM to identify each object uniquely. 
Syntax to Define Object in C++
className objectVariableName;
Example of object that maintains the record of students:


Explanation :
In above example class that has 2 fields ID and name. It creates instance of the class, Initializes the object and print the object value.