Guest User

Untitled

a guest
Apr 17th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. public class X
  2. {
  3. public void methodA() // Base class method
  4. {
  5. System.out.println ("hello, I'm methodA of class X");
  6. }
  7. }
  8.  
  9. public class Y extends X
  10. {
  11. public void methodA() // Derived Class method
  12. {
  13. System.out.println ("hello, I'm methodA of class Y");
  14. }
  15. }
  16. public class Z
  17. {
  18. public static void main (String args []) {
  19. X obj1 = new X(); // Reference and object X
  20. X obj2 = new Y(); // X reference but Y object
  21. obj1.methodA();
  22. obj2.methodA();
  23. }
  24. }
Add Comment
Please, Sign In to add comment