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 + "]";
}
}

最新文章

  1. 联想 Thinkpad X230 SLIC 2.1 Marker
  2. UILabel UISwitch UISegmentedControl UIAlertView
  3. 怎样更改wordpress登陆 URL防止恶意注册
  4. iOS下UITableView的单元格重用逻辑
  5. Python的Descriptor和Property混用
  6. iOS调用系统功能发邮件
  7. How to Release the Temp LOB Space and Avoid Hitting ORA-1652 (文档 ID 802897.1)
  8. java_线程安全-service
  9. scala学习笔记:变量声明中的模式
  10. m2e插件的新下载地址
  11. 《JavaScript设计模式与开发实践》读书笔记之策略模式
  12. Eclipse 打开js文件时出现 Could not open the editor...
  13. 系统引导器GRUB
  14. 内置函数 -- bytes -- 字节码与字符串相互转换
  15. Erlang和Web
  16. [UE4]Set Array Elem
  17. codeforces 877b
  18. gevent 实现io自动切换,gevent.join([]), gevent.spawn, 爬虫多并发的实现
  19. 精简计算UITableView文本高度
  20. SSRS 在订阅的时候,在头值中找到无效的字符。将不重新发送邮件

热门文章

  1. RF(IF 判断)
  2. Java——Spring超详细总结
  3. lammps 学习之:系统压力太大,导致原子丢失
  4. 【Spark】如何用Spark查询IP地址?
  5. 【matlab 基础篇 03】一文带你全面了解 plot 绘图函数的使用(超详细+图文并茂)
  6. Vulnhb 靶场系列:Jarbas1.0
  7. [hihoCoder1231 2015BeijingOnline]求圆与多边形公共部分的周长
  8. (Python基础教程之十三)Python中使用httplib2 – HTTP GET和POST示例
  9. Redux:data flow
  10. gRPC负载均衡(自定义负载均衡策略)