Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| |||||||||||
Interview Questions and Answers for 'Private' - 16 question(s) found - Order By Rating | |||||||||||
| |||||||||||
Ans. No | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  constructor  private constructor | |||||||||||
| |||||||||||
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  object oriented programming (oops)  oops concepts  inner classes   nested classes | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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   inner classes  nested classes | |||||||||||
| |||||||||||
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  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 Asked in 25 Companies | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes basic   frequent | |||||||||||
Very Frequently asked across all type of companies and across all levels. | |||||||||||
| |||||||||||
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   public vs private vs default vs protected Asked in 12 Companies basic   frequent | |||||||||||
Try 1 Question(s) Test | |||||||||||
| |||||||||||
Ans. With Java 9 we can declare interface methods as private | |||||||||||
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 | |||||||||||
| |||||||||||
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 Asked in 1 Companies basic | |||||||||||
Try 2 Question(s) Test | |||||||||||
| |||||||||||
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 Asked in 1 Companies | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
Frequently asked in face to face interviews. | |||||||||||
| |||||||||||
Ans. int count = 15; int[] fibonacci = new int[count]; fibonacci[0] = 0; fibonacci[1] = 1; for(int x=2; x < count; x++){ fibonacci[x] = fibonacci[x-1] + fibonacci[x-2]; } for(int x=0; x< count; x++){ System.out.print(fibonacci[x] + " "); } | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  ebay   fibonacci series Asked in 66 Companies basic   frequent | |||||||||||
| |||||||||||