我有这个代码块,它需要一个主方法才能运行。
public class Point {
private int xcoord;
private int ycoord;
public Point () {}
public Point (int x, int y) {}
public int getX () {
return xcoord;
}
public int getY () {
return ycoord;
}
public void moveUp(int amount) {}
public void moveDown(int amount) {}
public void moveRight(int amount) {}
public void moveLeft(int amount) {}
}
我尝试在public class Point
下面添加public static void main(String[] args){
,但它在整个程序中引起问题(说Public Point()需要声明为new),并且我关闭了MoveLeft
方法关闭冒号和public class
Point关闭冒号下面的主要方法,如下所示:
public class Point {
private int xcoord;
private int ycoord;
public static void main(String[] args){
public Point () {}
public Point (int x, int y) {}
public int getX () {
return xcoord;
}
public int getY () {
return ycoord;
}
public void moveUp(int amount) {}
public void moveDown(int amount) {}
public void moveRight(int amount) {}
public void moveLeft(int amount) {}
}
}
Main是一个方法,你不希望其他方法在它里面。
试试这样写:
public class Point {
private int xcoord;
private int ycoord;
public static void main(String[] args) {
} //End of main
//Now you add the rest of your methods
public Point(){
}
//And so on