public static final and private getter

Asked 2 years ago, Updated 2 years ago, 32 views

I have a question in Java

Question 1)

In the case of 'public static final variable', do not create an object It's called "Class Name".I learned to call it a variable.

Create a "private variable" object Is there a time that you like better, calling it "getter" or two ways?

For example, in the case of the 'public static final variable', is there a time when the value should not be changed unconditionally or is there a faster speed?

I don't know.Teachers

java

2022-09-22 20:11

1 Answers

It's called the public static final variable, which is a constant.

Constant, that is, the constant value. Since it is a static final, it is not a GC target. (This is why it is approached as a class, not as an object.) Method in Runtime Data Area Study area)

It has nothing to do with getter/setter encapsulating the data.

The question is correct if it is better to treat it as public image and access it as object.age and use getter/setter after private image.

The reason for using getter/setter is not a performance problem, but rather to adhere to the principle or rule of encapsulation from an object-oriented design point of view.


2022-09-22 20:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.