public class Circle {
private static int numberOfCircles = 0;
private static int ID;
public Point center = new Point();
public int radius;
public Circle(@NotNull Point getPoint, int r){
ID = ++numberOfCircles;
this.center.x = getPoint.x;
this.center.y = getPoint.y;
this.radius = r;
public static int getNumberOfCircles () { return numberOfCircles; }
public int getID() { return ID; }
我想在删除Circle对象时将numberOfCircles变量减1。这可能吗?如果是这样,请有人可以帮助我吗?预先感谢。
您可以在Circle类中添加delete()方法
public void delete() {
this.numberOfCircles--;
}
然后您可以像这样调用它:
// Create Circle
Circle c = new Circle(point, 2);
// Do something
...
// Delete circle
c.delete();
c = null;