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 ...

Get Object-Oriented Thought Process, The, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.