当前位置:网站首页>静态域与静态方法
静态域与静态方法
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
}
边栏推荐
猜你喜欢

7-2 拼题A打卡奖励 dp

gin_ gorm

1500w播放下还藏着什么热点?B站2个未来趋势你不得错过

微研所,微生物检验中常用的生化反应

Complete software development process

Test essential tool - postman practical tutorial

Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry

Selenium classic interview question - multi window switching solution

微生物健康,食品微生物检测为什么很重要

After working for 6 years, let's take stock of the golden rule of the workplace where workers mix up
随机推荐
Compile and install oh my Zsh
Basic knowledge 3 - standard unit library
微生物健康,食品微生物检测为什么很重要
Unknown database连接数据库错误
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number
laravel+redis 生成订单号-当天从1开始自增
[queue] 933 Number of Recent Calls
Composants de la grille de données portatifs
Handsontable data grid component
数据探索电商平台用户行为流失分析
数学知识:求组合数 IV—求组合数
Some essential differences
[Qt5 tab] tab label and content hierarchical analysis
Log4j2 ThreadContext日志链路追踪
[content of content type request header]
7-2 拼题A打卡奖励 dp
正向代理和反向代理快速理解
农产品换房?“变相”购房补贴!
electron之坑addon
视频教程 | 长安链推出系列视频教程合集(入门)