2015-04-20 15:36:01 -07:00
|
|
|
|
//: typeinfo/InterfaceViolation.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
// Sneaking around an interface.
|
|
|
|
|
import typeinfo.interfacea.*;
|
|
|
|
|
|
|
|
|
|
class B implements A {
|
|
|
|
|
public void f() {}
|
|
|
|
|
public void g() {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class InterfaceViolation {
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
A a = new B();
|
|
|
|
|
a.f();
|
|
|
|
|
// a.g(); // Compile error
|
|
|
|
|
System.out.println(a.getClass().getName());
|
|
|
|
|
if(a instanceof B) {
|
|
|
|
|
B b = (B)a;
|
|
|
|
|
b.g();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} /* Output:
|
|
|
|
|
B
|
|
|
|
|
*///:~
|