Horje
demonstrate constructor Code Example
demonstrate constructor
// C++ program to demonstrate constructors
 
#include <bits/stdc++.h>
using namespace std;
class Geeks
{
    public:
    int id;
     
    //Default Constructor
    Geeks()
    {
        cout << "Default Constructor called" << endl;
        id=-1;
    }
     
    //Parameterized Constructor
    Geeks(int x)
    {
        cout << "Parameterized Constructor called" << endl;
        id=x;
    }
};
int main() {
     
    // obj1 will call Default Constructor
    Geeks obj1;
    cout << "Geek id is: " <<obj1.id << endl;
     
    // obj1 will call Parameterized Constructor
    Geeks obj2(21);
    cout << "Geek id is: " <<obj2.id << endl;
    return 0;
}




Whatever

Related
mds_stores Code Example mds_stores Code Example
which is better for a better code.function or class Code Example which is better for a better code.function or class Code Example
Creality Ender 3 incl start kit Code Example Creality Ender 3 incl start kit Code Example
sydney cost of living Code Example sydney cost of living Code Example
tabla de conversión ascii/binario Code Example tabla de conversión ascii/binario Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7