Syntax Quiz 2, Step 5

Assignment:

Insert the method declaration into the class body.

My solution:

You've already written

public class QuizClass
  {
  private int instanceVar; 
  } 
and
 public void doSomething () 
   { 
   }
Now put them together as
public class QuizClass
  {
  private int instanceVar; 
  public void doSomething () 
     { 
     } 
  } 
(Note that all the "public" and "private" keywords are optional for purposes of this quiz.)

The order of the things inside a class body is fairly flexible: some authors prefer to put all the instance variables at the end, after all the methods; some prefer to put all the public things before all the private things; etc. I usually put the instance variables first, followed by methods.

Common mistakes:

Putting the method definition in the wrong place.
All method definitions must be inside the curly-braces of a class definition, but not inside anything else (e.g. another method definition).

Last modified:
Stephen Bloch / sbloch@adelphi.edu