Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Construct Destruct */
- #include <iostream>
- using namespace std;
- class MU_person
- {
- public:
- MU_person()
- {
- cout << "MU_person constructor" << endl;
- }
- ~ MU_person ()
- {
- cout << "MU_person destructor" << endl;
- }
- };
- class student: public MU_person
- {
- public:
- student()
- {
- cout << "student constructor" << endl;
- }
- ~student()
- {
- cout << "student destructor" << endl;
- }
- };
- int main(void)
- {
- cout << "Program starts." << endl;
- //MU_person d;
- student d;
- cout << "Program ends." << endl;
- return 0;
- }
- /* Construct Destruct 2 */
- #include <iostream>
- using namespace std;
- class MU_person
- {
- protected:
- long id;
- public:
- MU_person(long=10);
- };
- MU_person::MU_person(long x)
- {
- id=x;
- cout<< "MU person constructor " << id <<endl;
- }
- class student:public MU_person
- {
- private:
- double gpa;
- public:
- student(long=20 ,double=2.5);
- void display();
- };
- void student::display()
- {
- cout<< "id" << id <<endl;
- cout<< "gpa" << gpa <<endl;
- }
- student::student(long x,double g):MU_person(x)
- {
- gpa=g;
- cout<< "MU student constructor " << x << " " << g <<endl;
- }
- int main()
- {
- student m1(1111,2),m2(112),m3;
- m1.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement