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

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.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Private variable' - 3 question(s) found - Order By Rating

 Q1. Why can't we declare on outer class as private ?Core Java
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


Related Questions

 Can we declare a class private ?
 How can we hide a class in Java ?


 Q2. What happens to private variables during inheritance ?Core Java
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


Related Questions

 Can we access private members of the parent class ? i.e Are private members of the class visible in the derived class ?
 Why can't we declare on outer class as private ?
 Can we serialize objects with only private variables in Java ?


 Q3. Can we access private members of the parent class ? i.e Are private members of the class visible in the derived class ?Core Java
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


Related Questions

  Difference between Public, Private, Default and Protected ?
  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
  Enums cannot be declared ..
 What is the difference between these two method declarations ?

private static void method(String[] arg)

and

private static void method(String... arg)
  Can we declare interface methods as private ?
  How can we create objects if we make the constructor private ?
  Why are Getter and Setter better than directly changing and retrieving fields ?

or

What is the significance of variable hiding in Java ?

or

Why it's preferred to keep variables private and allow their access through getter and setter methods ?
  enums are intrinsically ..
  Can we instantiate the object of derived class if parent constructor is protected ?
  Can we declare an abstract method private ?



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: