Question 3-1

What distinguishes the purpose of a class method from an instance method? That is, how should you decide whether a particular behavior should be an instance method or a class method? (I am not asking how they are syntactically distinguished in Java. The syntactic distinction is that a class method includes a static keyword in its declaration, while an instance method does not.)

Solution

An instance method is a behavior that applies to specific objects of a class, while a class method is a behavior that applies to the class as a whole. When you call an instance method, you must apply it to a particular object (e.g., file.readInt(), where file is an InputFile object); but a class method can be applied to the entire class (e.g., IO.readInt(), which uses the readInt() class method in the IO class).

Back to 8:00 Quiz 3