fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.lang.reflect.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Method mfoo = Derived.class.getMethod("foo");
  14. boolean ovrFoo = mfoo.getDeclaringClass() != Base.class;
  15. Method mbar = Derived.class.getMethod("bar");
  16. boolean ovrBar = mbar.getDeclaringClass() != Base.class;
  17. System.out.println("Have override for foo: "+ovrFoo);
  18. System.out.println("Have override for bar: "+ovrBar);
  19. }
  20. }
  21.  
  22. class Base {
  23. public void foo() {}
  24. public void bar() {}
  25. }
  26. class Derived extends Base {
  27. @Override
  28. public void bar() {}
  29. }
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
Have override for foo: false
Have override for bar: true