You are here: Home / Topics / What are the various access specifiers in Java?

What are the various access specifiers in Java?

Filed under: JAVA Interview Questions on 2022-07-02 16:07:16

Access specifiers in java are the keywords which define the access scope of the function. It can be used before a class or a method. There are basically 4 types of access specifiers in java: –

  • Public: – class, methods, and fields are accessible from anywhere.
  • Protected: – methods and fields are accessed from the same class to which they belong. Even from the subclass and class from the same package. Any outside class cannot access the methods and fields.
  • Default: – only from the same package, the methods and fields be accessed and not from the outside package.
  • Private: – the methods and fields can be only accessed from the same class to which they belong.
About Author:
V
Vishal Gupta     View Profile
Hi, I am Vishal Gupta. I like this Website for learning MCQs. This website is good for preparation.