Pages

Friday, May 16, 2025

Predicting the output of Friend class and function problem 1 in OOPs

 #include <iostream>

using namespace std;

class Parent {
public:
    Parent() {
        cout << "constructor of parent\n";
    }
    // destructor of Parent class
    ~Parent() {
        cout << "destructor of parent\n";
    }
};

class Child : public Parent {
public:
    Child() {
        cout << "constructor of child\n";
       
    }
     
    //Destructor of Child
    ~Child() {
        cout << "destructor of child\n";
    }


};

int main() {
    Child ch1;

    return 0;
}


OUTPUT:
constructor of parent
constructor of child
destructor of child
destructor of parent

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...