Public
Public
is the most open access modifier
. If a variable/attribute has a public
modifier, then any other object can easily access it via the .
(dot) operator.
Below are major things you need to keep in mind when using the public
keyword.
- There can only be one
public
class in a single file in Java. - The file name should be the same as the class name.
- It is considered bad practice to make more public attributes and class methods than necessary.