当前位置:网站首页>静态域与静态方法
静态域与静态方法
2022-07-01 01:11:00 【冥王哈迪尔】
静态域
class Employee {
private static int nextId = 1;
private int id;
}
- 每一个雇员对象都有一个自己的id域,但这个类的所有实例共享一个nextId域
- 即,如果有1000个Employee类的对象,则有1000个实例域Id,但只有一个静态域nextId
- 即使没有一个雇员对象,静态域nextId也存在
- 静态域属于类,不属于任何独立的对象
- 在绝大多数面向对象程序设计语言中,静态域被称为类域
静态常量
- 静态变量用的极少,但静态常量用得多。
静态方法
- 一种不能向对象实施操作的方法
静态方法是没有this参数的方法
- 静态方法不能访问实例域,但可以访问自身类中的静态域
public static int getNextId(){
return nextId; //return static field
}
边栏推荐
- 【队列】933. Number of Recent Calls
- Log4j2 ThreadContext日志链路追踪
- electron之坑addon
- QT web development - VIDEO - Notes
- Thinking brought by strictmode -strictmode principle (5)
- PHP array splicing MySQL in statement
- 用 Flutter 的 Canvas 画点有趣的图形
- Test essential tool - postman practical tutorial
- Some items of OCR
- Mathematical knowledge: 01 sequence satisfying conditions - find combinatorial number
猜你喜欢
[fundamentals of wireless communication-14]: illustrated mobile communication technology and application development-2-the first generation mobile analog communication big brother
Log logrus third party library usage
gin_gorm
Gin configuration file
Uniapp official component clicking item is invalid, solution
electron之坑addon
正向代理和反向代理快速理解
Sun Yuchen told Swiss media Bilan that the bear market will not last long
Lecun, a Turing Award winner, pointed out that the future of AI lies in self-learning, and the company has embarked on the journey
3dsmax plug-in development traversal node object and object acquisition and inode transformation matrix description
随机推荐
[deepin] common sets
zabbix如何配置告警短信?(预警短信通知设置流程)
哪有什么未来可期,不过是打工人临死前最后的幻想罢了
Institute of Microbiology, commonly used biochemical reactions in microbiological testing
小程序中实现excel数据的批量导入
【Proteus仿真】Arduino UNO +74C922键盘解码驱动4X4矩阵键盘
There is no future to be expected. It is just the last fantasy of a migrant worker before he dies
【栈】921. Minimum Add to Make Parentheses Valid
Log4j2 ThreadContext日志链路追踪
PHP通过第三方插件爬取数据
Log4j2 threadcontext log link tracking
软件测试的可持续发展,必须要学会敲代码?
Sécurité et santé microbiennes, qu'est - ce que le traitement biologique?
视频教程 | 长安链推出系列视频教程合集(入门)
3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全
【agora】用户管理
laravel+redis 生成订单号-当天从1开始自增
思特奇加入openGauss开源社区,共同推动数据库产业生态发展
Thinking brought by strictmode -strictmode principle (5)
Use strictmode strictmode principle (1)