Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestSuperToSubclass {
- public static void main(String[] args) {
- final TestSuperToSubclass instance = new SubClass();
- instance.superClassMethod();
- }
- private void superClassMethod() {
- if (this instanceof SubClass) {
- System.out.println(((SubClass) this).field);
- } else {
- System.err.println("Unexpected subclass type: " + this.getClass().getName());
- }
- }
- }
- class SubClass extends TestSuperToSubclass {
- protected String field = "Test value.";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement