Skip to content

Instantly share code, notes, and snippets.

@jsyeo
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save jsyeo/122565cb929558d846df to your computer and use it in GitHub Desktop.

Select an option

Save jsyeo/122565cb929558d846df to your computer and use it in GitHub Desktop.
Class Hierarchy Analysis Example
public class Main {
public static void main(String[] args) {
H h = new H();
h.m();
// receiver has a declared class H, which is a subclass of C and H does not override method m
// therefore we are sure we are calling C.m here.
A a = new C();
a.m();
// We can be sure we are calling C.m here as A is never instantiated.
}
}
class H extends F {}
class G extends F {}
class F extends C {
@Override
void p() {
}
}
class E extends C {
@Override
void m() {
}
}
class D extends B {
}
class C extends A {
@Override
void m() {
}
}
class B extends A {
@Override
void m() {
}
}
class A {
void m() {
}
void p() {
}
}
@jsyeo
Copy link
Author

jsyeo commented Aug 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment