fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. class A{
  9. public String show(D obj){
  10. return ("A and D");
  11. }
  12. public String show(A obj){
  13. return ("A and A");
  14. }
  15. }
  16. class B extends A{
  17. public String show(B obj){
  18. return ("B and B");
  19. }
  20. public String show(A obj){
  21. return ("B and A");
  22. }
  23. }
  24. class C extends B{}
  25. class D extends B{}
  26.  
  27.  
  28. /* Name of the class has to be "Main" only if the class is public. */
  29. class Ideone
  30. {
  31. public static void main (String[] args) throws java.lang.Exception
  32. {
  33. A a1 = new A();
  34. A a2 = new B();
  35. B b = new B();
  36. C c = new C();
  37. D d = new D();
  38. System.out.println(a1.show(b));
  39. System.out.println(a1.show(c));
  40. System.out.println(a1.show(d));
  41. System.out.println(a2.show(b));
  42. System.out.println(a2.show(c));
  43. System.out.println(a2.show(d));
  44. System.out.println(b.show(b));
  45. System.out.println(b.show(c));
  46. System.out.println(b.show(d));
  47. }
  48. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
A and A
A and A
A and D
B and A
B and A
A and D
B and B
B and B
A and D