programplug Logo




C++ Constructor


Constructor is a special type of method that is used to initialize the object.A constructor does not have any return type.
A constructor has a same name as the class in which it declare or use.Constructor can not be abstracted,static,final or synchronized.


Non Parameterized Constructor

#include 
class Student  
{  
   public:  
	Student()    
	{    
	  cout<<"Non Parameterized Constructor" << endl;    
	}    
};  
void main()   
{  
	Student s; //creating an object  
}   

output:
Non Parameterized Constructor


Parameterized Constructor

#include 
class Student 
{
   public:
       int id;   
       string name;
       float percentage;
       Student(int i, string n, float s)  
        {  
            id = i;  
            name = n;  
            percentage = s;
        }  
        void display()  
        {  
            cout<< id<<"  "<< name<<"  "<< salary<< endl;  
        }  
};
void main() 
{
    Student s1 = Student(1, "Rahul", 79.4); //creating an object of Employee 
    Student s2 = Student(2, "Mohit", 87.67); 
    s1.display();  
    s2.display();  
}    

output:
1 Rahul 79.4
2 Mohit 87.67







Our Services

Developing Cheapest Websites
Offer Digital Marketing
Provide College Projects
Attractive Website Developing
Summer Training,Industrial Training
SCO,SMO

Contact Us

Dehradun Uttarakhand India
www.programplug.com
info@programplug.com
08534019974
Designed By : Mridul Gupta

Other Link

About Us

Contact Us

Disclaimer

Privacy Policy