Question from the C++ - Fundamentals test

What does the following code display ? class A { public: A() { f(); } virtual void f() { cout << "A" << endl; } }; class B : public A { public: void f() { cout << "B" << endl; } }; int main() { A a; B b; A* pa(&b); pa->f(); return 0; }

Expert

What does the following code display ?

class A {
public:
    A() {f();}
    virtual void f() {cout << "A";}
};

class B : public A {
public:
    void f() {cout << "B";}
};

int main() {
    A a;
    B b;
    A* pa(&b);
    pa->f();
    return 0;
}
Author: SamuelStatus: PublishedQuestion passed 286 times
Edit
0
Community Evaluations
developer avatar
Antoine
31/03/2024
Since there is endl for each cout, output promt not valid