What are modifiers?
Previous | Home | Next |
Java provides a number of access modifiers to help you set the level of access you want for classes as well as the fields, methods and constructors in your classes.
There are four access modifiers in java:
public :-Fields, methods and constructors declared public within a public class are visible to any class in the
Java program.
private :Fields, methods or constructors declared private are strictly controlled, which means they cannot be accesses by anywhere outside the enclosing class.
protected :-used on members accessible only within its package and its subclasses
default:-Any class, field, method or constructor that has no declared access modifier is accessible only by classes in the same package. The default modifier is not used for fields and methods
within an interface.
Previous | Home | Next |