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

I want to run a simple hello world java (HelloWorld.java) program using a batch file. How can i run it and how to construct a batch file.

1 Answers   Infosys,


What is default exception handling in java?

0 Answers  


State some situations where exceptions may arise in java?

0 Answers  


What is the current version of java?

0 Answers  


Explain constructors and types of constructors in java.

0 Answers  


what is translator and it types

1 Answers  


Write a program in java to establish a connection between client and server?

0 Answers  


What is the final method?

0 Answers  


what is difference between type 4 driver and type 1 driver?

2 Answers   CMC, CTS, IBM, JK Technosoft, Napier Healthcare,


There are two classes named classa and classb. Both classes are in the same package. Can a private member of classa can be accessed by an object of classb?

0 Answers  


class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_class extends c{ m2(){ } pulic static void main(){ ...My_class a = new my_class(); super.super.super.m2(); is this is leagal if not find what is the legal procedure in order to call A's version of m2(); }

8 Answers   Logica CMG,


What do you understand by overloading and overriding in java?

0 Answers  


Categories