当前位置:网站首页>static类变量快速入门
static类变量快速入门
2022-04-23 19:04:00 【十九线小程序员】
类变量的叫法:静态变量/类变量/类属性
类属性概念:它是属于类的一个独立的空间(这个空间在类加载的时候就被创建了),这个类创建的每个对象都可以对它进行操作(共享)。
类变量定义和访问:
定义语法:
//static 是修饰符,可以修饰属性和方法
public static int totalNum = 0;
访问语法(有两种访问方式):
1,通过类名直接访问
2,通过对象名来访问
class Test {
//类名.类变量
//说明:类变量是随着类加载而创建的,所以即使没有创建对象实例也可以访问。
public static void main(System[] args){
//通过类名来访问
System.out.println(A.name);
A a = new A();
//通过对象名来访问
System.out.println(a.name);
}
}
class A {
//类变量
String static name = "小平";
}
注意事项:
类变量的访问,必须遵守相关的访问权限。
版权声明
本文为[十九线小程序员]所创,转载请带上原文链接,感谢
https://blog.csdn.net/hv102/article/details/124361148
边栏推荐
- Use of kotlin collaboration in the project
- : app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
- Go language GUI framework Fyne Chinese garbled or not displayed
- Nacos cluster construction and MySQL persistence configuration
- Iptables - L executes slowly
- Dynamically add and delete layouts
- Using 8266 as serial port debugging tool
- ESP32 LVGL8. 1 - slider slider (slider 22)
- Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
- Machine learning practice - naive Bayes
猜你喜欢
根据快递单号查询物流查询更新量
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
ESP32 LVGL8. 1 - arc (arc 19)
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
mysql_linux版本的下載及安裝詳解
12个例子夯实promise基础
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
Introduction to ROS learning notes (I)
Druid SQL和Security在美团点评的实践
Chondroitin sulfate in vitreous
随机推荐
Deeply understand what new and make in golang are and what are the differences?
腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
Esp32 (UART ecoh) - serial port echo worm learning (2)
開關電源設計分享及電源設計技巧圖解
Esp32 (UART event) - serial port event learning (1)
mysql_ Download and installation of Linux version
Coolweather is revised and connected to the wind weather interface to realize the broken line diagram of temperature
The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics
Yyds dry goods inventory stringprep --- Internet string preparation
Nacos作为服务配置中心实战
ESP32 LVGL8. 1 - textarea text area (textarea 26)
The type initializer for ‘Gdip‘ threw an exception
ESP32 LVGL8. 1 - roller rolling (roller 24)
Practice of Druid SQL and security in meituan review
Redis common interview questions
Feature selection feature_ selection--SelectKBest
ESP32 LVGL8. 1 - calendar (calendar 25)
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
ESP32 LVGL8. 1 - input devices (input devices 18)
Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time