OnJava8-Examples/typeinfo/InterfaceViolation.java
2015-11-14 16:18:05 -08:00

26 lines
479 B
Java

// typeinfo/InterfaceViolation.java
// ©2016 MindView LLC: see Copyright.txt
// 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
*/