To my understanding of the error, the most common cause is because I haven't included "public static void main (String[] args)", but I've done this prior to discovering the error, which is leaving me stumped. Can anyone help me out?
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();
}
}
You have several options to run your program this. One of them is:
basketBallTester.java
file, and place there your class basketBallTester
. basketBallTester.java
and basketBall.java
java basketBallTester
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.