当前位置:网站首页>静态域与静态方法
静态域与静态方法
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
}
边栏推荐
- 软件测试的可持续发展,必须要学会敲代码?
- Sécurité et santé microbiennes, qu'est - ce que le traitement biologique?
- 医疗HIS行业短信发送解决方案
- 【多源bfs】934. Shortest Bridge
- Creating ASCII art with C #
- 测试必备工具—Postman实战教程
- Understanding and application of Qt5 layout in creation
- Try new possibilities
- Handsontable數據網格組件
- 【队列】933. Number of Recent Calls
猜你喜欢

Selenium经典面试题-多窗口切换解决方案

测试必备工具-Postman实战教程

AS400 API 从零到一的整个历程

There is no future to be expected. It is just the last fantasy of a migrant worker before he dies
![[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number](/img/51/e48e222c14f4a4e9f2be91a677033f.png)
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number

Basic knowledge 3 - standard unit library

Qt5 mvc: revealing the secrets of data visualization

正向代理和反向代理快速理解
![[fundamentals of wireless communication-15]: illustrated mobile communication technology and application development-3-overview of digital communication 2G GSM, CDMA, 3G wdcma/cdma200/td-scdma, 4G LTE](/img/22/1efa444220131359b06005f597c9db.png)
[fundamentals of wireless communication-15]: illustrated mobile communication technology and application development-3-overview of digital communication 2G GSM, CDMA, 3G wdcma/cdma200/td-scdma, 4G LTE

农产品换房?“变相”购房补贴!
随机推荐
What will Web3 bring in the future?
Qt5 mvc: revealing the secrets of data visualization
Using recyclerreview to show banner is very simple
gin 配置文件
【Proteus仿真】Arduino UNO +74C922键盘解码驱动4X4矩阵键盘
VirtualBox 安装增强功能
Compile and install oh my Zsh
数据探索电商平台用户行为流失分析
gin_ gorm
Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
Electron pit Addon
System. Csrebot for commandline
物业怎么发短信通知给业主?
New opportunities for vr/ar brought by metauniverse
哪有什么未来可期,不过是打工人临死前最后的幻想罢了
7-2 punch in reward DP for puzzle a
Mathematical knowledge: finding combinatorial number III - finding combinatorial number
Unknown database连接数据库错误
QT web development - VIDEO - Notes
【队列】933. Number of Recent Calls