Like Nick said , the main() method of your class is the one that's
called when, on a command line (like DOS or bash) you type "java
myClass". If you create a main() method you make that class runnable;
however, it's usually more correct to create a separate class
(something like RunPoint) to do this. For the sake of simplicity, you
can start by creating the main() method directly on that class, just
to try it out. Here are a few examples, you can copy and paste it into
your current code so you can test it:
public static void main(String[] args){
//create a new Point by calling it's constructor method (Point())
Point myPoint = new Point();
//let's see what it's current coordinates and color are
//for that we'll call the getX(), getY() and getColor() methods
System.out.println("Coordinates: "+myPoint.getX()+" "+myPoint.getY());
System.out.println("Color: "+myPoint.getColor());
//let's change it's attributes (coordinates and color)
myPoint.setX(10);
myPoint.setY(20);
myPoint.setColor("blue");
//now let's verify the changes
System.out.println("New coordinates: "+myPoint.getX()+" "+myPoint.getY());
System.out.println("New color: "+myPoint.getColor());
//let's use the other constructor to create a new point
Point myOtherPoint = new Point(5,15,"red");
//let's see what the new point looks like
System.out.println("Other point's coordinates: "+myOtherPoint.getX()+"
"+myOtherPoint.getY());
System.out.println("Other point's color: "+myOtherPoint.getColor());
}
Hope it helped, try them out and post your doubts :) |