Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
Java Language EssentialsDownload tutorial zip fileEmail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
Course Notes
  


Instance methods page 13 of 37


The type of methods we're designing at present are called instance methods because they are invoked relative to a particular instance of a class. For this reason, an instance method can reference an instance variable directly, without the this qualifier, as long as there is no variable name conflict, for example,


  void bark() {
    System.out.println(barkSound);
  }

In this case, the no-argument version of bark() references the instance variable barkSound directly. As implied by the setBark() definition, however, we could also write bark() as follows:


  void bark() {
    System.out.println(this.barkSound);
  }

Here, there are no other variables within (local to) bark() named barkSound, so these implementations are equivalent.


copyright 1996-2000 Magelang Institute dba jGuru


Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
PrivacyLegalContact