Java - Interview Questions and Answers for 'Access specifier' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Access specifier' - 12 question(s) found - Order By Newest

 Q1. What are points to consider in terms of access modifier when we are overriding any method?Core Java
Admin
info@buggybread.com
Ans. 1. Overriding method can not be more restrictive than the overridden method.

reason : in case of polymorphism , at object creation jvm look for actual runtime object. jvm does not look for reference type and while calling methods it look for overridden method.

If by means subclass were allowed to change the access modifier on the overriding method, then suddenly at runtime when the JVM invokes the true objects version of the method rather than the reference types version then it will be problematic

2. In case of subclass and superclass define in different package, we can override only those method which have public or protected access.

3. We can not override any private method because private methods can not be inherited and if method can not be inherited then method can not be overridden.

  Sample Code for Overriding

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   overriding   access specifier   inheritence   oops   polymorphism   runtime polymorphism     Genpact

Try 2 Question(s) Test


Very Frequently asked across all type of companies and across all levels.
  Q2. Difference between Public, Private, Default and Protected ?Core Java
Anonymous
Ans. 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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oop   access specifier   public   private   default   protected   basic interview question     HCL Technologies  Tata Consultancy (TCS)  IBM  Wipro  Deegit  Argonne National Laboratory  Motorola Mobility  Accenture  Deegit  Cerner      basic        frequent

Try 1 Question(s) Test


 Q3. Which access specifier can be used with Class ?
Anonymous
Ans. For top level class we can only use "public" and "default". We can use private with inner class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   class   access specifier   inner class      basic        frequent


 Q4. Can we reduce the visibility of the inherited or overridden method ?Core Java
Anonymous
Ans. No.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   access specifier   overriding   overridding   inheritence   yes-no


 Q5. Can we instantiate the object of derived class if parent constructor is protected ?Core Java
Anonymous
Ans. Yes, as protected constructor is accessible in sub class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   constructor   access specifier   protected   yes-no  private constructor


 Q6. Which access specifiers can be used with top level class ?

a. public or default
b. public or private
c. public or protected
d. protected or default
Core Java
Anonymous
Ans. public or default

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     access specifier   oops   java   class


 Q7. Can we reduce the visibility of the overridden method ?Core Java
Anonymous
Ans. No

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     overriding   access specifier   oops   java   yes-no


 Q8. What will happen if we make the constructor private ?Core Java
Anonymous
Ans. We can't create the objects directly by invoking new operator.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   constructor   access specifier   private     Jabong.com      basic

Try 2 Question(s) Test


 Q9. Can we declare an abstract method private ?
Anonymous
Ans. No Abstract methods can only be declared protected or public.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   abstract   oops   access specifier   private   yes-no      intermediate        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Name few access and non access Class Modifiers ?
Admin
info@buggybread.com
Ans. private , public and protected are access modifiers.

final and abstract are non access modifiers.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   access specifiers   access modifiers   modifiers   access control


 Q11. What is the difference between public class and class ?Core Java
Admin
info@buggybread.com
Ans. Class without any access specifier has the default scope i.e it can be accessed by any class within same package.

Class declared public can be accessed from anywhere.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   access specifier   access modifiers   public class   class

Try 1 Question(s) Test


 Q12. What access the variable gets if we don't provide any access specifier ?Core Java2017-02-12 09:33:06

Ans. It gets the default access i.e package protected.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     access specifiers  default Access specifier      Basic




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: