How does access modifiers work?



How does access modifiers work?..

Answer / 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

More Core Java Interview Questions

How to create an interface?

0 Answers  


What is a constructor, constructor overloading in java?

0 Answers  


State the difference between strings and arrays.

0 Answers   Syntel, Visa,


what are the methods of an object class?

3 Answers  


What is adapter class?

12 Answers  






my method "abc" return array of interface "xyz" and "pqr" is abstract class implements abc and class "jkl" extends pqr My problem 1) when i call abc it retrun array xyz how can i do this hint xyz refer_xyz = new jkl(); but i can't create array. 2)I want to access method of jkl using reference of xyz??

1 Answers  


How do you use compareto in java?

0 Answers  


difference between vectorlist and hash

1 Answers   TCS,


What is the difference between static method and instance method in Java?

0 Answers   SwanSoft Technologies,


Is hashset ordered java?

0 Answers  


What is the use of volatile in java?

0 Answers  


Can you call one constructor from another if a class has multiple constructors?

0 Answers  


Categories