Access modifiers

is it compulsory to use access modifiers in front of every method or class in java?

No. No access modifier makes a class or member “package-private” so every class in the same package can access it but a class from another package can’t.

1 Like

No, it is not compulsory to use access modifiers in front of every method or class in Java. Access modifiers in Java, such as “public,” “private,” “protected,” and “default,” are optional and used to control the visibility and accessibility of class members. If an access modifier is not specified, the default “package-private” access level is used.

1 Like