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

Search Java Interview Questions


 2137 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 'Private' - 16 question(s) found - Order By Newest

Very Frequently asked across all type of companies and across all levels.
  Q1. 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


 Q2. Can we declare interface methods as private ?
Anonymous
Ans. No.

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

   Like      Discuss      Correct / Improve     java   oops   interfaces   yes-no   private


 Q3. How can we create objects if we make the constructor private ?Core Java
Anonymous
Ans. We can do so through a static public member method or static block.

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

   Like      Discuss      Correct / Improve     java   oops   static   constructor   static method   static block  private     Jabong.com


 Q4. 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


 Q5. 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


 Q6. 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


 Q7. Can we access private members of the parent class ? i.e Are private members of the class visible in the derived class ?Core Java2016-08-04 09:24:34

Ans. No, If both Parent and Derived are outer classes.

public class Vehicle {
   private static String manufacturingDate = "2016";
}

public class Car extends Vehicle{
   public static void main(String args[]){
      System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible
   }
}

Yes, If derived is the inner class of Parent.

public class Vehicle {
   private static String manufacturingDate = "2016";
   static public class Car extends Vehicle{
      public static void main(String args[]){
         System.out.println(manufacturingDate); // no problem
      }
   }
}

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

   Like      Discuss      Correct / Improve     private members   private methods   private variables   inheritance   members visibility      basic        frequent


 Q8. Have you ever felt the need of keeping the constructor private ?Design2016-11-15 09:40:58

Ans. Yes, When either we don't want an object to be created ( class having all static elements and hence not required ) or object to be created using a static method or static block. One such example could be a situation when we would like app to load objects at start up and we would like to restrict new object creation by any request.

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

   Like      Discuss      Correct / Improve     private constructor  constructor


 Q9. Write a Program to print factorial of a number using recursionCore Java2017-01-29 17:47:20

Ans. public class BuggyBread {
public static void main(String args[]) {
System.out.println(factorial(5));
}

private static int factorial(int number){
if(number == 1){
return 1;
} else {
return number * factorial(number - 1);
}
}
}

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

   Like      Discuss      Correct / Improve     recursion     PrimeFocus Technologies  Aavanor System  Mobicip  CMSS Private Limited  Intrepid Pursuits  Indus Valley Partners  Sunquest Information Systems  Linchpin  Riverbed Technology  Knoldus Software  Sopra Steria  Sunquest Information Systems  OpenBet  DMX Technologies  Whitesnow Software Consultancy  NextSphere  Clearwater Analytics  Obelisk Infosystems  iNautix Technologies  Andesa Services  NextSphere  MobileIron  Wolfram Research  Spillman Technologies



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Can a constructor have a private access specifier ?Core Java2017-03-22 19:49:54

Ans. Yes, declaring a constructor private means disabling the creation of object that way using new operator.

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

   Like      Discuss      Correct / Improve     constructor  private constructor


 Q11. What happens to private variables during inheritance ?Core Java2017-06-07 16:35:35

Ans. Private variables are not inherited. They are simply ignored and not made part of the derived object body.

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

   Like      Discuss      Correct / Improve     private variables  inheritance


 Q12. Can we declare a class private ?Core Java2017-06-07 16:40:34

Ans. We can declare an inner class as private and hence would be restricting it's access from outside. We cannot make outer class as private.

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

   Like      Discuss      Correct / Improve     private class


 Q13. Why can't we declare on outer class as private ?Core Java2017-06-07 16:41:57

Ans. Making an outer class as private will make it inaccessible from anywhere and would make it useless.

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

   Like      Discuss      Correct / Improve     private variables


 Q14. How can we hide a class in Java ?Core Java2017-06-07 16:42:57

Ans. By encapsulating it within another class and declaring it private. In such a case, it will only be accessible through parent class or parent class object.

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

   Like      Discuss      Correct / Improve     private class   private inner class  class hiding  encapsulation


 Q15. Can we instantiate the object of derived class if parent constructor is private ?Core Java2017-08-14 08:37:37

Ans. No

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

   Like      Discuss      Correct / Improve     constructor  private constructor


 Q16. How can we create objects if we make the constructor private ?Core Java
a. We can't create objects if constructor is private
b. We can only create objects if we follow singleton pattern
c. We can only create one object
d. We can create new object through static method or static block

Ans.d. We can create new object through static method or static block



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

1 person from Kansas City are looking for questions for 'Private'. Connect with them to better prepare for your interview.
X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: