Advertisement
JeffGrigg

TestSuperToSubclass

Sep 10th, 2017
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.55 KB | None | 0 0
  1. public class TestSuperToSubclass {
  2.    
  3.     public static void main(String[] args) {
  4.         final TestSuperToSubclass instance = new SubClass();
  5.         instance.superClassMethod();
  6.     }
  7.  
  8.     private void superClassMethod() {
  9.         if (this instanceof SubClass) {
  10.             System.out.println(((SubClass) this).field);
  11.         } else {
  12.             System.err.println("Unexpected subclass type: " + this.getClass().getName());
  13.         }
  14.     }
  15. }
  16.  
  17. class SubClass extends TestSuperToSubclass {
  18.     protected String field = "Test value.";
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement