NTU-OOP-Tuts-2024-Cpp/T9Q2/main.cpp

22 lines
578 B
C++
Raw Permalink Normal View History

2024-11-05 10:34:51 +08:00
#include <iostream>
using namespace std;
class BC {
public:
2024-11-07 12:18:48 +08:00
// Inheritance in C++ is not similar to Java. The method above will not be automatically overrride
2024-11-05 10:34:51 +08:00
void show(void) { cout << " \n I am in base class.."; }
2024-11-07 12:18:48 +08:00
// Unless we add the keyword virtual on it. Comment the line above and uncomment the line below to test.
// virtual void show(void) { cout << " \n I am in base class.."; }
2024-11-05 10:34:51 +08:00
};
class DC : public BC {
public:
void show(void) { cout << " \n I am derived class.."; }
};
int main()
{
BC* ptr1;
DC dobj;
ptr1 = &dobj;
ptr1->show();
}