Object Oriented Scope
In object oriented programming, methods and variables have various scope. Scope means that the method or variable may or may not be directly accessable to other objects or classes. Classes that do not have instances may be accessable to the system.
Class variables and class methods are associated with a class. An instance of the class (object) is not required to use these variables or metnods. Class methodc cannot access instance variables or metnods, only class variables and methods.
Instance variables and instance methods are associated with a specific object. They can access class variables and methods.
Private variables and private methods are only accessible to the object they are contained in.
Protected variables and protected methods are accessible by the class they are in and inheriting classes (sub classes).
Public variables and public methods are accessible outside the object they are contained in. They are accessible to any other object.
The process of providing a public interface to interact with the object while hiding other information inside the object.
Java Variables and Scope
There are three types of variable scope in Java.