Back to Top

Sunday, 15 January 2012

JAVA : Access Specifiers in Java

public access

Fields, methods and constructors declared public (least restrictive) within a public class are visible to any class in the Java program, whether these classes are in the same package or in another package.


private access

The private (most restrictive) fields or methods cannot be used for classes and Interfaces. It also cannot be used for fields and methods within an interface. Fields, methods or constructors declared private are strictly controlled, which means they cannot be accesses by anywhere outside the enclosing class. A standard design strategy is to make all fields private and provide public getter methods for them.


protected access

The protected fields or methods cannot be used for classes and Interfaces. It also cannot be used for fields and methods within an interface. Fields, methods and constructors declared protected in a superclass can be accessed only by subclasses in other packages. Classes in the same package can also access protected fields, methods and constructors as well, even if they are not a subclass of the protected member’s class.


default access

Java provides a default specifier which is used when no access modifier is present. 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.

8 Responses to “ JAVA : Access Specifiers in Java ”

Scientech Easy said...
20 May 2018 at 10:16 This comment has been removed by the author.

Scientech Easy said...
20 May 2018 at 10:17 This comment has been removed by the author.

Scientech Easy said...
20 May 2018 at 10:19

Nice tutorial-Scientech Easy


Dipanwita said...
10 August 2018 at 15:42

this is a superb blog. will recommend it to everybody. java training in chennai


aditya said...
21 December 2018 at 15:50 This comment has been removed by the author.

Venkatesh CS said...
29 May 2019 at 11:49

Access specifier concept have understood for me.Thanks.
Java Training in OMR


Nisha San said...
6 July 2019 at 17:28

Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai


hitesh kumar said...
30 December 2019 at 18:58

Thanks for sharing this Article Related to Access Modifiers in Java


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar