fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.io.*;
  4. class Base
  5. {
  6. protected void foo()
  7. {
  8. System.out.println("Base foo()");
  9. }
  10.  
  11. private void bar()
  12. {
  13. System.out.println("Base bar()");
  14. }
  15.  
  16. public static void main(String[] args) {
  17. Base child = new Child();
  18. child.foo();
  19. child.bar();
  20. System.out.println("Why did child.foo overide base.foo but child.bar did not overide base.bar ?");
  21. }
  22.  
  23. }
  24.  
  25. class Child extends Base
  26. {
  27. protected void foo()
  28. {
  29. System.out.println("Child foo()");
  30. }
  31.  
  32. protected void bar()
  33. {
  34. System.out.println("Child bar() ");
  35. }
  36. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Child foo()
Base bar()
Why did child.foo overide base.foo but child.bar did not overide base.bar ?