Default constructor with proper example in cpp in bangla


 #include<iostream>
using namespace std;
class prime{
public:
        int id; //Data Members
        string name; //Data Members
        prime(){//Default Constructor
                id = 12345;
                name ="Bangladesh";
        }
        void display()//Output Function
        {
                cout<<id<<endl;
                cout<<name<<endl;
        }
};
int main()
{
        prime obj;
        obj.display();
        return 0;
}

No comments:

Post a Comment