Class In Object oriented Programming languages

Posted by Tushar Bedekar
Basically, there  are various different definition of the classes in object-oriented programming language. Some basic definition are as follows:-


  • The class is said to be the collection of an object.
  • The class is said to be the collection of the data members and their member functions that are used to access and modify those data members.
  • The class is sometimes said to be the blueprint of an object.
     class Box
    {
       public:
       double length;   // Length of a box
       double breadth;  // Breadth of a box
       double height;   // Height of a box
     };
The C++ makes use of the keyword class followed by its identifier(Name of the class). Basically the class is said to be the collection of similar kind of an object.

The C++ classes have 3 different types of access specifier. They are as follows:
  • Public 
  • Private 
  • And protected. 

Keywords: private and public

Keyword private makes data and functions private and keyword public makes data and functions public. Private data and functions are accessible inside that class only whereas, public data and functions are accessible both inside and outside the class. This feature in OOP is known as data hiding. If programmer mistakenly tries to access private data outside the class, compiler shows an error which prevents the misuse of data. Generally, data are private and functions are public.

Keyword: Protected

But however the C++ makes use of another special kind of keyword (access specifier) Protected which is used to hide the data members and members function from being accessed from other class but allows the access from only the child class.

Data Members:

data member may be of any type, including classes already defined, pointers to objects of any type, or even references to objects of any type.Data members may be private or public, but are usually held private so that values may only be changed at the discretion of the class function members.

Member Function:

Member functions are operators and functions that are declared as members of a class. Member functions do not include operators and functions declared with the friend specifier. These are called friends of a class. You can declare a member function as static; this is called a static member function.


Further Topics will be covered in the next post.If you have any doubt regarding this section fell free to contact us     you can also join us at  Discussion Forum or E-mail us at
admin@allaboutcomputing.net

0 comments:

Post a comment

back to top