Created
May 25, 2011 08:25
-
-
Save ussy/990568 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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