Pages

Friday, May 16, 2025

Predicting the output of friend function and class in OOPs - 02

 #include <iostream>

using namespace std;

class Base
{
public:
    virtual void print() {
        cout << "Base\n";
    }
};

class Derived : public Base {
public:
    void print() {
        cout << "Derived\n";
    }


};
int main() {
    Base *b = new Derived();
    b->print();

    delete b;
    return 0;
}

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...