The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.


Operations on Objects

Even though we can't print times in an optimal format, we can still write methods that manipulate Time objects. In the next few sections, I will demonstrate several of the possible interfaces for methods that operate on objects. For some operations, you will have a choice of several possible interfaces, so you should consider the pros and cons of each of these:

pure function
Takes objects and/or primitives as arguments but does not modify the objects. The return value is either a primitive or a new object created inside the method.
modifier
Takes objects as arguments and modifies some or all of them. Often returns void.
fill-in method
One of the arguments is an "empty" object that gets filled in by the method. Technically, this is a type of modifier.


Last Update: 2011-01-24