AtkinsSJ

Java's insane overriding

Jun 7th, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. // Java is insane.
  2. // If you create an instance of SubClass, and call testMethod() on it,
  3. // it will output "In the subclass".
  4.  
  5. public class SuperClass
  6. {
  7.     public void testMethod()
  8.     {
  9.         this.overriddenMethod();
  10.     }
  11.  
  12.     public void overriddenMethod()
  13.     {
  14.         System.out.println("In the superclass");
  15.     }
  16. }
  17.  
  18. public class SubClass extends SuperClass
  19. {
  20.     public void overriddenMethod()
  21.     {
  22.         System.out.println("In the subclass");
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment