All methods in Java "live in" a class, although one class may contain many methods. If you use BlueJ's "New Class" button, you'll get something that looks like this:
/** * Write a description of class MyClass here. * * @author (your name) * @version (a version number or a date) */ public class MyClass { // instance variables - replace the example below with your own private int x; /** * Constructor for objects of class MyClass */ public MyClass() { // initialise instance variables x = 0; } /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public int sampleMethod(int y) { // put your code here return x + y; } }Of this, the first few lines are comments about the class: you should fill these in with your name, the date, and the purpose of the class (if any). A lot of the rest of this stuff isn't relevant to us yet, and we can either delete it or ignore it. For now, a minimal class definition looks like
public class MyClass { // put a method definition here // put another method definition here }Last modified: Fri Jan 30 11:31:26 EST 2009 Stephen Bloch / sbloch@adelphi.edu