In Java, do accessor methods always need to return a value? -


i wondering if accessor methods in java need return value. because "access" method print etc.

for example, method below considered accessor method in class?

public static void getcapacity(){     system.out.print("capacity 0");  } 

access methods needed value. call method value, , continue work him (or, example, compare something).

one oop principles the principle of encapsulation - values of closed fields of class using access methods.

here we expect see informative message:

public void printcapacity(){     system.out.print("capacity 0");  }  

in method, we expect value:

public int getcapacity(){     return this.capacity; } 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -