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

3Sum - Leetcode solution - How i turned into two-pointer approach?

  class Solution {     public List < List < Integer >> threeSum ( int [] nums ) {         Arrays . sort (nums); // first sort...