title: Only allow some classes to call a method in Java
body: <p>Lets say I have a structure like this:   </p>
  
  <p>Object A contains an instance of Object B<br>
  Object B contains an instance of Object C</p>
  
  <p>Object D extends Object C</p>
  
  <p>I have an instance of object D that other people will be writing and using in my program.  There is some information about that object that I want to have but not give them access to though.  What I am currently doing is storing that information and methods in Object B which contains Object D instead of Object C.</p>
  
  <p>The problem is if I make it private so that Object D can not use any of the methods, then I can not access them from anywhere else in the program either.  Is there any way to make it so that D can not access a method but other classes can?</p>