What is the difference between variables declared as final and private?

Asked

Viewed 134 times

6

What is the difference between these two types of variables and why can’t they be accessed in certain parts of the code? I read about private, public and abstract methods, but did not understand the use of the ending.

1 answer

8


  1. A variable of the type final can only be initialized once, either through an initializer or through an assignment.
  2. A variable of the type private can only be directly modified and accessed within the class itself. To access and modify a variable of this type, outside the class in question, one must resort to getters and setters of the variable.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.