Private Implementation Methods

 <  Day Day Up  >  

Private Implementation Methods

Although all the methods discussed so far in this chapter are defined as public , not all the methods in a class are part of the public interface. Some methods in a class are meant to be hidden from other classes. These methods are declared as private :

 
 private void turnRight(){ } private void turnLeft() { } 

These private methods are simply meant to be part of the implementation, and not the public interface. You might ask who invokes these methods, if no other class can. The answer is simple ”you might have already surmised that these methods are called internally from the class itself. For example, these methods could be called from within the method giveDestination :

 
 public void giveDestination (){     .. some code     turnRight();     turnLeft();     .. some more code } 

The point here is that private methods are strictly part of the implementation, and are not accessible by other classes.

 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net