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

Search Interview Questions


 3235 questions in repository.
 There are more than 200 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 members' - 1 question(s) found - Order By Newest

 Q1. 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  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes      basic        frequent


Related Questions

  Difference between Public, Private, Default and Protected ?
  Enums cannot be declared ..
  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 ..
 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 ?
  Can we instantiate the object of derived class if parent constructor is protected ?
  How can we test methods individually which are not visible or declared private ?
  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




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