Difference between public/private/global variables in Apex.
Private: This is the default and means that the method or variable is accessible only within the Apex. If you do not specify an access modifier, the method or variable is private.
Protected: This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class. You can only use this access modifier for instance methods and member variables.
Public: This means the method or variable can be used by any Apex in this application or namespace.
Global: This means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application. This access modifier should be used for any method that needs to be referenced outside of the application, either in the SOAP API or by other Apex code. If you declare a method or variable as global, you must also declare the class that contains it as global.
Check out this link: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm