Saturday, December 24, 2011

What do you understand by private, protected and public ?

These are accessibility modifiers.
private:
Private is the most restrictive. Private variables and methods can be accessed with in the class only. We can not access private variables and methods outside the class.

public:
Public is the least restrictive. Public classes can be accessed with in the package and outside the package also.

protected:
It is available to the all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.

default:
It is available to the all classes in the same package.