就我对错误的理解而言,最常见的原因是因为我没有包含“public static void main(String [] args)”,但是在发现错误之前已经做到了这一点,这让我很困惑。谁能帮我吗?

import java.io.*;
class basketBall
{
    private String name;
    private double number;
    private String team;

    // declare getter method public
    public String getName()
    {
        return name;
    }

    // declare setter method public
    public void setName(String n)
    {
        name = n;
    }

    // declare getter method public
    public String getTeam()
    {
        return team;
    }

    // declare setter method public
    public void setTeam(String t)
    {
        team = t;
    }

    // declare getter method public
    public double getNumber()
    {
        return number;
    }

    // declare setter method public
    public void setNumber(double num)
    {
        number = num;
    }

    // declare dribble method
    void dribble()
    {
        System.out.println (name + ", " + number + " dribbles down the court...");
    }

    // declare shoot method
    void shoot()
    {
        System.out.println (name + " shoots... And he scores, for the " + team + "'s!");
    }
}

// test class for basketBall class
class basketBallTester
{
    public static void main (String[] args)
    {
        //construct player and fills in its objects
        basketBall Player1 = new basketBall();
        // fill in objects of player1
        Player1.setName("Ethan");
    Player1.setTeam("Vikings");
    Player1.setNumber(15);

        // call methods
        Player1.dribble();
        Player1.shoot();
    }
}

最佳答案

您可以通过多种方法来运行程序。其中之一是:

  • 创建一个单独的basketBallTester.java文件,并在其中放置您的类basketBallTester
  • 编译两个文件:basketBallTester.javabasketBall.java
  • 使用java basketBallTester运行您的程序
  • 09-10 02:31