Since it was unclear how to use java properly, such as static, I investigated it.
static
If you add a static modifier to a method or member variable, it becomes a static method or static variable. What changes with the static modifier is that you can access the method and member variables without new.
http://www.366service.com/jp/qa/75864cfae2ee945a362e5a9818cabb58
In other words, use it when you want to share common methods and variables between classes. I wrote an article about exchanging data through the Application class before, but it's the same. https://qiita.com/QiitaD/items/549fb2143b2774c30d72
(Even so, the static uncle laughed as expected ...)
Another thing is that it can be used without instantiation. It seems that the Utility class etc. do not need to be instantiated because the processing is completed by the method alone, that is, the usage is fixed when the class is defined. In that case, it is also static. https://teratail.com/questions/13203
I understand static, but I don't know public or final yet. Needless to say, public and private are used properly from the viewpoint of object-oriented design. But I don't know why protected or defaults exist (although I know there are differences in access), so I'd like to find out too.
Recommended Posts