Computer Applications

Name various visibility modifiers in a class.

Encapsulation & Inheritance in Java

4 Likes

Answer

The various visibility modifiers in a class are as follows:

  1. public — The public members are accessible in all the classes whether a subclass or any other class in same package or another package.
  2. private — The private members are accessible only inside their own class and nowhere else.
  3. protected — The protected members are accessible inside all the classes in their own package as well as in all subclasses of their class.
  4. default — The default members are accessible inside all the classes of the same package.

Answered By

4 Likes


Related Questions