fork download
  1. class Exercise {
  2. abstract static class Top {
  3. public void f(Object o) {
  4. System.out.println("Top");
  5. }
  6. }
  7.  
  8. static class Sub extends Top {
  9. public void f(String s) {
  10. System.out.println("Sub");
  11. }
  12. }
  13.  
  14. public static void main(String[] args) {
  15. Sub sub = new Sub();
  16. Top top = sub;
  17.  
  18. String stringAsString = "someString";
  19. Object stringAsObject = stringAsString;
  20.  
  21. top.f(stringAsObject);
  22. sub.f(stringAsObject);
  23.  
  24. sub.f(stringAsString);
  25. top.f(stringAsString);
  26. }
  27. }
  28.  
Success #stdin #stdout 0.06s 32440KB
stdin
Standard input is empty
stdout
Top
Top
Sub
Top