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

Why is method overloading not possible by changing the return type in java?

594


What is integer valueof?

645


Why do we declare a class static?

548


Can we change the value of static variable?

502


What is sorting in java?

536






What is the use of coding?

522


Why destructor is not used in java?

523


Can we create a class inside a class in java?

550


Does list maintain insertion order java?

539


What is the disadvantage of java?

508


What do you understand by the term string pool?

567


I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?

525


What does %d do in java?

581


How to invoke external process in java.

570


What 5 doubled?

510