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. abstract class A
  8. {
  9. public void Testme(A other)
  10. {
  11. System.out.println("value from this: " + Value() + " value from other: " + other.Value());
  12. }
  13.  
  14. abstract protected String Value();
  15. }
  16.  
  17. class B extends A
  18. {
  19. protected String Value()
  20. {
  21. return "B class";
  22. }
  23. }
  24.  
  25. class C extends A
  26. {
  27. protected String Value()
  28. {
  29. return "C class";
  30. }
  31. }
  32.  
  33. /* Name of the class has to be "Main" only if the class is public. */
  34. class Program
  35. {
  36. public static void main (String[] args) throws java.lang.Exception
  37. {
  38. B b = new B();
  39. C c = new C();
  40. b.Testme(c);
  41. }
  42. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
value from this: B class value from other: C class