To access a variable in a class in Java, is it better to return its value via a method, or just acces it via myClass.variable? -
i think title says all. maybe should ask: ever bad not use method return variable, or value? example 2-d point class x , y variable.
is there wrong using mypoint.x
x variable of mypoint
opposed mypoint.xvalue()
, returns mypoint.x
?
you should make code, encapsulated, use setters , getters.
Comments
Post a Comment