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

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