Java - Interview Questions and Answers on Access Specifiers

Q1.  Difference between Public, Private, Default and Protected ?


Private - Not accessible outside object scope. 
Public - Accessible from anywhere. 
Default - Accessible from anywhere within same package.
Protected - Accessible from object and the sub class objects.

Q2.  Can we reduce the visibility of the overridden method ?

Ans. No

Q3.  Which access specifier can be used with Class ?

Ans. For top level class we can only use "public" and "default". We can use private with inner class.

Q4.  Can we reduce the visibility of the inherited or overridden method ?

Ans. No.

Q5.  What will happen if we make the constructor private ?

Ans. We can't create the objects directly by invoking new operator.

Q6.  Can we instantiate the object of derived class if parent constructor is protected ?

Ans. No

Q7.  Can we declare an abstract method private ?

Ans. No Abstract methods can only be declared protected or public.