Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class Sound {
  2.  
  3. private int sound;
  4.  
  5. void setSound(final int sound) {
  6. this.sound = sound;
  7. }
  8. }
  9.  
  10. class NoSound extends Sound {
  11.  
  12. @Override
  13. void setSound(final int sound) {
  14. // empty, we dont want to set sound!
  15. }
  16.  
  17. public void music() {
  18. super.setSound(5) // this makes a refference to the super -> Sound#setSound method, so this will set the sound variable to a desired value
  19. setSound(5) // while this makes a refference to THIS instance, so it will reffer to NoSound#setSound so our sound value wont change
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement