Normally
you don’t want to make instance variables public, and access them through
methods. An exception to this rule would be when you want to make a constant
variable. When you make an instance variable private you can only access it
inside the class. This means if I make a child class I cannot use that private
variable in that class. If for some reason you want a variable to be accessible
in a child class and package, but nowhere else, you can make it protected. The
last option is having no access modifier. This makes it so you can access that
variable only in the same package.
No comments:
Post a Comment