Access modifiers like
public have no effect on the resource requirements of a Java program. They exist largely as documentation and aids to understanding for human readers and writers of the code. Even when information about the status of a field or method is retained at runtime, it's likely to be stored in a bitfield-like structure, so either value takes the same amount of memory.
In short, making things
private does not optimize computer memory (RAM) in any way. It can, however, be better for human memory, because an API with fewer visible members is easier to understand and easier to remember than an API with everything