fork download
  1. #include<iostream>
  2. class Base{
  3. private:
  4. int _privateVar;
  5.  
  6. protected:
  7. int protectedVar;
  8.  
  9. public:
  10. int publicVar;
  11. Base():protectedVar(100){}
  12. virtual void publicMethod(int someValue, int anotherValue)
  13. {
  14. protectedVar = someValue;
  15. publicVar = anotherValue;
  16. std::cout<<"In Base";
  17. }
  18. };
  19.  
  20. class Dervied: public Base{
  21.  
  22. protected:
  23. int protectedVar;
  24. virtual void publicMethod(int someValue, int anotherValue)
  25. {
  26. //protectedVar = someValue;
  27. // publicVar = anotherValue;
  28. std::cout<<"In Derived";
  29. std::cout<<protectedVar ;
  30. }
  31. public:
  32. Dervied():protectedVar(1000){}
  33. };
  34.  
  35. int main(void)
  36. {
  37. Dervied d;
  38. Base *ptr = &d;
  39. ptr->publicMethod(10, 20);
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
In Derived1000