CodesJava

Easy learning with example program codes

CPP Object Class


CPP introduced the features of OOPs Concept, i.e, CPP is an object-oriented programming language which uses classes and objects for computations.

CPP Class:

A collection of Objects is termed as Class in OOPs concept. Every class has its own unique and distinguishable attributes and methods.

Syntax:

class ClassName:

<statement-1> 

    . 

    . 

    . 

    <statement-N> 

 

CPP Object:

Anything that has state and behavior can be termed as an Object, be it physical or logical. An Object is an entity mentioned in OOPs concept and is frequently found in CPP codes.

Creating an object in CPP is similar as calling a function. The objects attributes can then be accessed by using the object name prefix.

Example:

#include <iostream.h>
using namespace std;
 
class Employees
{
public:  
string Name;  
float Salary;
void insert(string n, float s)    
{    
Name = n;    
Salary = s;  
}    
void details()
{
cout << "Employee Name : " << Name << endl;
cout << "Employee Salary: " << Salary << "\n\n";
}
};
int main()
{
Employees e1;   
Employees e2; 
e1.insert("Khush", 10000);    
e2.insert("Raam", 20000);    
e1.details();    
e2.details();    
return 0;
}

Output

Employee Name : Khush                                 
Employee Salary: 10000                               
 
Employee Name : Raam                                                 
Employee Salary: 20000
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki