Home » Expert's columns

Concepts of Object Oriented Programming System (OOPS)

In this article, we are going to learn about the Object Oriented Programming System (OOPS) in C++ programming language.
Submitted by Brajesh Kumar Shrivash, on March 15, 2018

The basic concepts of object oriented programming are:

  1. Object
  2. Class
  3. Inheritance
  4. Data Abstraction
  5. Data Encapsulation
  6. Polymorphism

1) OBJECT

An object is an instance of a class. Object is one of the basic elements of OOP’s; it is most significant unit as without creating object, we cannot access the functionality of the class. After defining the class, we create its object to get accessibility of data member and member functions of respective class.

Below mentioned is an example of how to create an object?

Syntax:

class_name object_name

It is very easy to create an object of a pre-defined class. To create the object, we need to write the name of the class first then name of the object. User can put the name of object as per their choice.

For example: we are assuming that the student class is already exists and we can create its object like in this way,

student s;   //s is an object of class student

We can create more than one object of a class. For example,

student s,s1,s2,s3;

2) CLASS

Class is a user define data type; we call it user define because a user can define the data and functions as per their requirements. To create a class, we first write class (class is a keyword) and then name of the class (mentioned below in example). Basically class divides in two main sections - data member and member function. Class is a unit which combines data member and member function together in a single unit.

Syntax

    class class_name
    {
      //data members section
      private:
         ...;                             
         ...;
   
      // member functions section
      public:
         ...;
         ...;
    };

Syntax:

#include <iostream>
using namespace std;

class student
{	
	private:
		//sname and srollno are data members
		char sname [30];
		int    srollno;

		public:
			void getinput()
			{
				// get name from the Keyboard 
				cout<<"Input Students Name: ";  
				cin>>sname;
				
				// get rollno from the Keyboard
				cout<<"Input Students Roll Number: ";
				cin>>srollno;	          
			}
			void getoutput()
			{
				// shows name on monitor
				cout<<"Students Name:"<< sname << endl;     
				// shows rollno on monitor
				cout<<"Student Roll Number:"<<srollno<< endl;   
			}
};

//main code
int main()
{
	// s is an object of student class
	student s;                  

	// the getinput method is being called
	s.getinput();             
	
	// the getoutput method is being called
	s.getoutput();
	
	return 0;
}

Output

Input Students Name: DUGGU 
Input Students Roll Number: 101 
Students Name:DUGGU
Student Roll Number:101



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.