Encapsulation in java

* What is Encapsulation?

*What is Access Modifier?

*How many access Modifier In java?
Ans.: There are 4 access modifier in java. they are-

  1. default
  2. public
  3. protected
  4. private 
*What is the rules of Access modifier?
Ans:Visible to the package. the default. No modifiers are needed.
Visible to the class only (private).
Visible to the world (public).
Visible to the package and all subclasses (protected).

* What is the inheritance of the access modifier?
Ans.: The following rules for inherited methods are enforced:
1. Methods declared public in a superclass also must be public in all subclasses.
2. Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.
3. Methods declared without access control (no modifier was used) can be declared more private in subclasses.
4. Methods declared private are not inherited at all, so there is no rule for them.

Reactions

Post a Comment

1 Comments