Object Oriented ScopeIn 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 ScopeClass 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 ScopeInstance variables and instance methods are associated with a specific object. They can access class variables and methods. Private ScopePrivate variables and private methods are only accessible to the object they are contained in. Protected ScopeProtected variables and protected methods are accessible by the class they are in and inheriting classes (sub classes). Public ScopePublic variables and public methods are accessible outside the object they are contained in. They are accessible to any other object. EncapsulationThe process of providing a public interface to interact with the object while hiding other information inside the object. Java Variables and ScopeThere are three types of variable scope in Java.
|