根据我对错误的理解,最常见的原因是因为我没有包含" 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();
}
}
答案 0 :(得分:4)
您可以通过多种方式运行程序。其中之一是:
basketBallTester.java
文件,并将您的课程basketBallTester
放在那里。basketBallTester.java
和basketBall.java
java basketBallTester