fork(1) download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Test{
  5. // private:
  6. // int x;
  7.  
  8. public:
  9. //void setValue(int a){
  10. // x=a;
  11. //}
  12.  
  13. //int getValue(){
  14. // return x;
  15. //}
  16.  
  17. void display(){
  18. displayb();
  19. }
  20.  
  21. virtual void displayb(){
  22. cout<<"From base class\n";
  23. }
  24. };
  25.  
  26. class Result: public Test{
  27. public:
  28. void displayb(){
  29. cout<<"From derived class";
  30. }
  31. };
  32.  
  33. int main() {
  34. Test obj;
  35. Result res;
  36. obj.display();
  37. res.display();
  38. // cout<<obj.getValue();
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5508KB
stdin
Standard input is empty
stdout
From base class
From derived class