0 votes
1 view
in Java by (2.4k points)
What are the differences between the specifiers?

1 Answer

0 votes
by (5.4k points)

Java provides the programmer with a multitude of options to adjust the accessibility of an element in his code:

  • Public: The public specifier is used when there isn't a requirement for emphasis on security where the particular method, class or field is concerned. The elements defined by this access specifier and can be accessed by all elements of the program. 
  • Protected: These can be accessed within the same class, by the subclasses or within the classes of the same package that the container class or protected class belongs to.
  • Default: When an access specifier hasn't been explicitly specified, it is called a default class. These can be accessed within the same package.
  • Private: Only accessible within the same class. These are not visible in their subclasses either.

    

All of these access specifiers have different roles in a real-world scenario and are widely used in a production environment. If you're looking to learn java, you should make a habit of using all these classes according to the use-case which is presented to you.  

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 20 in Java by angadmishra (2.4k points)
0 votes
1 answer
asked Feb 20 in Java by angadmishra (2.4k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...