Describe about the term Access Protection ?
Global variables are a typical cause of bugs in most programming languages. A few unknown function can modify the value of a variable while the programmer isn't expecting it to change. This plays all sorts of havoc.
Most OOP languages involving Java permit you to protect variables from external modification. This permit you to guarantee in which your class remains consistent along with what you think it is as long as the techniques of the class themselves are bug-free. For instance, in the Car class we'd like to make sure that no block of code in a few other class is permited to make the speed greater than the maximum speed. We need a way to make the subsequent illegal:
Car c = new Car("New York A234 567", 100.0);
c.speed = 150.0;
This code violates the constraints we've placed on the class. We need to permit the compiler to enforce these constraints.
A class presents a picture of itself to the world. (This picture is sometimes known as an interface, other than the word interface has a more exact meaning in Java.) This picture says in which the class has certain methods and certain fields. Everything else about the class involved the detailed workings of the class's methods are hidden. As long as the picture the class displays to the world doesn't change, the programmer can change how the class implements that picture. Among other advantages this permit the programmer to change and improve the algorithms a class uses without worrying that a few piece of code depends in unforeseen ways on the details of the algorithm used. This is known as encapsulation.
Another way to think about encapsulation is in which a class signs a contract along with all the other classes in the program. This contract says in which a class has methods with unambiguous names that take particular types of arguments and return a particular type of value. The contract might also say that a class has fields along with given names and of a given type. However the contract does not specify how the methods are implemented. However, it does not say that there aren't other private fields and methods that the class may use. A contract guarantees the presence of certain methods and fields. It does not exclude all other techniques and fields. This contract is implemented by access protection. Every class, field and techniques in a Java program is defined as either public, private, protected or unspecified.
You're closer to your immediate family (your parents and your children) than you are to your cousins. You're closer to your cousins than to the common public at large, but there are some things you don't tell anybody. Therefore, your family is not my family.