How does access modifiers work?

Answer Posted / javamasque

Public: It is the highest visibility access modifier. It makes visible the class members (variables/methods) to any classes (child/non-child) present within same or any package.
Protected: It has lesser visibility than public access modifier. It makes visible the class members (variables/methods) to sub-classes within same or different package and it also make visible in any class of same package.
Default: It has lesser visibility than protected access modifier. It makes visible the class members (variables/methods) to any classes within same package only.
Private: It has least visibility than all access modifiers. It makes visible the class members (variables/methods) within same class only.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which number is denoted by leading 0x or 0x in java?

553


What is a finally block?

550


what invokes a threads run() method? : Java thread

565


Can you tell me range of byte?

554


What is square root in java?

582






What are the different collection views provided by maps?

557


What is r in java?

587


What is regex used for?

538


What is lossy conversion in java?

550


What is the purpose of declaring a variable as final?

480


What are the differences between path and classpath variables?

484


Can a class be defined inside an interface?

555


What is the benefit of inner / nested classes ?

519


What is an object in java and how is it created?

580


What package is math in java?

529