标签:double test main super rri his static nbsp system
static关键字的应用:使用静态的变量可以实现 "累加" 的效果
package com.aff.statics; public class TestCircle { public static void main(String[] args) { Circle c1 = new Circle(2.0); Circle c2 = new Circle(2.2); System.out.println(Circle.getTotal()); Circle.show(); c1.setInfo("小圆-->效原"); Circle.show(); c2.show(); } } class Circle { private double radius;// 半径 private static String info = "效原"; private static int total = 0;// 因为total是static的,在内存中独一份,所以可以用来记录创建的对象的个数 public Circle(double radius) { super(); this.radius = radius; total++; } 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; } public static void show() { System.out.println(info); } @Override public String toString() { return "Circle [radius=" + radius + "]"; } }
标签:double test main super rri his static nbsp system
原文地址:https://www.cnblogs.com/afangfang/p/12526474.html