Modifiers of Java
Modifiers of Java
Modifiers :
1. private
2. default
3. protected
4. public
private :
it is a keyword, an access modifier.
any member of a class prefixed with private can
be used only within the same class, we cannot
use a private member directly anywhere else.
public :
1. What is the difference between private and default? explain with example
2. How protected is different from default and public? explain with
example programs.
3. Can we restrict the object creation of a class outside a package ? justify
with an example program.
4. Can we restrict the object creation of a class such that, the object must not
be created anywhere except within the class ? justify with an example
5. How do we use a protected member in a class present outside a package?
explain with an example.