静态变量在内存中只有一份,所有可以用来记录创建类的个数
package day091;
public class Circle {
private double radius;//半径
private static String info = "我是一个圆";
private static int total = 0;//因为total是static的,在内存中只有一份,所有可以用来记录创建类的个数
public Circle(double radius) {
this.radius = radius;
total++;
}
public static void show() {
System.out.println(info);
}
@Override
public String toString() {
return "Circle [radius=" + radius + "]";
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public static String getInfo() {
return info;
}
public static void setInfo(String info) {
Circle.info = info;
}
public static int getTotal() {
return total;
}
public static void setTotal(int total) {
Circle.total = total;
}
}