fork download
  1. #include<iostream>
  2. using namespace std;
  3. class parent {
  4. public:
  5. void print() {
  6. cout << "Parent" << endl;
  7. }
  8. };
  9.  
  10. class child : public parent {
  11. public:
  12. void print() {
  13. cout << "Child" << endl;
  14. }
  15. };
  16.  
  17. int main() {
  18. child C;
  19. parent P;
  20. P.print(); // Output: "Parent"
  21. C.print(); // Output: "Child"
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5436KB
stdin
Standard input is empty
stdout
Parent
Child