Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: find in unordered_map c++ 
Cpp :: C++ continue with for loop 
Cpp :: all permutations with repetition C++ 
Cpp :: how to say hello world in c++ 
Cpp :: how to initialize 2d array with values c++ 
Cpp :: how to find the length of an array in cpp 
Cpp :: c++ loop through list 
Cpp :: Give an algorithm for finding the ith-to-last node in a singly linked list in which the last node is indicated by a null next reference. 
Cpp :: array of Methods c++ 
Cpp :: how to use command line arguments with integers in c++ 
Cpp :: c++ remove chars from string 
Cpp :: how to convert string to int in c++ 
Cpp :: c++ integer array 
Cpp :: run c++ program mac 
Cpp :: overload array operator cpp 
Cpp :: how to declare a vector of int in c++ 
Cpp :: prevent getting data from data-tooltip-content tippyjs 
Cpp :: User defined functions and variables in C++ programming 
Cpp :: 1768. Merge Strings Alternately leetcode solution in c++ 
Cpp :: z transfrom mathlab 
Cpp :: c++ comment out multiple lines 
Cpp :: c++ define constant in class header 
Cpp :: c++ call by value 
Cpp :: how to find product of a given numbers in c++ 
Cpp :: how to find factorial of number in c++ 
Cpp :: pointers c++ 
Cpp :: options select from array 
Cpp :: public method 
Cpp :: define a type in c++ 
Cpp :: cpp compare strings 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =