在哪里添加主方法Java



我有这个代码块,它需要一个主方法才能运行。

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

相关内容

  • 没有找到相关文章

最新更新