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

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...