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. interface Relatable{
  8. public void large(Relatable other);
  9. }
  10.  
  11. class A implements Relatable{
  12.  
  13. public void large(Relatable other) {
  14. A obj = (A) other;
  15. System.out.println("Hello");
  16. }
  17.  
  18. }
  19.  
  20. class B implements Relatable{
  21. //int p = 100;
  22. public void large(Relatable other) {
  23. System.out.println("Hi");
  24. }
  25. }
  26.  
  27. /* Name of the class has to be "Main" only if the class is public. */
  28. class Ideone
  29. {
  30. public static void main (String[] args) throws java.lang.Exception
  31. {
  32. Relatable a = new A();
  33. Relatable b = new B();
  34.  
  35. a.large(b);
  36. }
  37. }
Runtime error #stdin #stdout #stderr 0.06s 4386816KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.ClassCastException: B cannot be cast to A
	at A.large(Main.java:14)
	at Ideone.main(Main.java:35)