public static void main means that you are writing an executable program. So in the Amoebamath program, everytime you run it, every statement in the "main" function will be executed. You can have classes without a main method, though, like the following example.
Quote:
public class Point{
int x;
int y;
public Point(int x, int y){
this.x = x;
this.y = y
}
public void getPoint(){
System.out.println(x + " " + y);
}
public int getX(){
return x;
}
public static int getDifference(int x, int y){
return x-y;
}
}
|
This does not have a main method, so if you try to run it, nothing will happen, because you have not provided any instructions for it to run. You could use the Point class in a program with a main method, if you wanted to. For instance:
[qoute]
public class Demo{
public static void main(String args[]){
Point p = new Point(2, 2);
System.out.println(p.getX());
System.out.println(Point.getDifference(4, 2);
}
}
[/quote]
So now when I run this program, I am actually running an executable program. By contrast, try running Point and you'll see that nothing happens.
Static methods require an instance of an object to run. See Point's getX(); if I haven't created a Point object, then I don't have a Point to get x from. Imagine if I asked you the area of a circle that doesnt exist; it doesnt make sense to ask that question. Nonstatic methods dont require that an object be created. I wrote a method called getDifference, to which I provided two ints. The ints I provided had nothing to do with a Point object. Main methods are static because by definition they are run before any objects are created. Void means that the method does not return anything. Does that helpd clear things up? Good luck