State the significance of public, private, protected class.

Solution:

  • Public : When a class is public, the public class is visible in other packages, the field is visible everywhere.
  • Private : Private variables or methods can be used by an instance of the same class only which declares the variable or method. A private feature can be accessed by the class that owns the feature.
  • Protected : Protected variable is available to all classes in the same package. It is also available to all subclasses of the class that owns the protected feature. Subclasses that reside in a different package also is provided with the access from the class that owns the protected feature.
0 answers