Class and object

                      Class and object


Class is a logical entity while object is a physical entity. Class is like a user defined data type. Object take up space in memory. For example, the room in which we are sitting is a class and the objects of this class are black-board, chalk, tables, chairs, fans etc.

A class in C++ has two types of members: data members and function members. (Just like in the classroom in which we are sitting, there are two types of members: student member and faculty member). Generally, we put data members in private section of a class and function members in public section of class.

  • Whatever we write under private section of a class, can be accessed only within the class and not outside the class.
  • Whatever we write under public section of a class, can be accessed from both within the class and outside the class.

Code:-
class abc
{
private:
int x; //member data of class abc is x
public:
void fun() //member function of class abc is fun
{
x=10;
cout<<x;
}
}; //class closed


void main()
{
abc ob; //ob is object of class abc
ob.fun(); //member function fun of class abc is called using object ob of class abc
}

Output: 10

The other will have other major projects and will have different functionality

Comments

Popular posts from this blog

Inline and Friend Operators

Function overloading and Operator overloading

Exceptional Handling