static关键字的应用
2024-09-06 08:09:59
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 + "]";
}
}
最新文章
- 联想 Thinkpad X230 SLIC 2.1 Marker
- UILabel UISwitch UISegmentedControl UIAlertView
- 怎样更改wordpress登陆 URL防止恶意注册
- iOS下UITableView的单元格重用逻辑
- Python的Descriptor和Property混用
- iOS调用系统功能发邮件
- How to Release the Temp LOB Space and Avoid Hitting ORA-1652 (文档 ID 802897.1)
- java_线程安全-service
- scala学习笔记:变量声明中的模式
- m2e插件的新下载地址
- 《JavaScript设计模式与开发实践》读书笔记之策略模式
- Eclipse 打开js文件时出现 Could not open the editor...
- 系统引导器GRUB
- 内置函数 -- bytes -- 字节码与字符串相互转换
- Erlang和Web
- [UE4]Set Array Elem
- codeforces 877b
- gevent 实现io自动切换,gevent.join([]), gevent.spawn, 爬虫多并发的实现
- 精简计算UITableView文本高度
- SSRS 在订阅的时候,在头值中找到无效的字符。将不重新发送邮件
热门文章
- RF(IF 判断)
- Java——Spring超详细总结
- lammps 学习之:系统压力太大,导致原子丢失
- 【Spark】如何用Spark查询IP地址?
- 【matlab 基础篇 03】一文带你全面了解 plot 绘图函数的使用(超详细+图文并茂)
- Vulnhb 靶场系列:Jarbas1.0
- [hihoCoder1231 2015BeijingOnline]求圆与多边形公共部分的周长
- (Python基础教程之十三)Python中使用httplib2 – HTTP GET和POST示例
- Redux:data flow
- gRPC负载均衡(自定义负载均衡策略)