Skip to content

Instantly share code, notes, and snippets.

@ussy
Created May 25, 2011 08:25
Show Gist options
  • Save ussy/990568 to your computer and use it in GitHub Desktop.
Save ussy/990568 to your computer and use it in GitHub Desktop.
package com.example;
import java.lang.reflect.Method;
public class Client {
public static void main(String[] args) throws Exception {
A a = new A();
B b = new B();
Method m = A.class.getMethod("hello");
System.out.println(m.invoke(a)); // A
System.out.println(m.invoke(b)); // B super.hello()?
}
public static class A {
public String hello() {
return "A";
}
}
public static class B extends A {
@Override
public String hello() {
return "B";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment