java - making a simple ball class for moving ball but not moving -
i'm making simple program moving ball, unfortunately it's not moving, when put values x=5, , y=4 after running program it's showing "ball @ (0.0,0.0)" on console please mistake.
public class ball { private double x,y; //private variables... //creating constructors.. public void ball(double x, double y) { this.x=x; this.y=y; } public void ball() { x=5.0; y=4.0; } //getter , setter private variables.... public double getx() { return x; } public void setx() { this.x=x; } public double gety() { return y; } public void sety() { this.y=y; } public void setxy(double x, double y) { this.x=x; this.y=y; } public void move(double xdisp, double ydisp) { x+=xdisp; y+=xdisp; } public string tostring() { return "ball @ ("+x+","+y+")"; } public static void main(string[] args) { ball b=new ball(); system.out.println(b); }
}
you don't have constructors, default 1 called, nothing x
, y
.
in order have intended to, should provide constructor (you're there), remove void
modifier:
public void ball()
now, constructor. note should same other meant-to-be-constructor.
Comments
Post a Comment