当前位置:网站首页>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
边栏推荐
- Sentinel rule persistence into Nacos
- ESP32 LVGL8. 1 - textarea text area (textarea 26)
- 8266 obtain 18b20 temperature
- Simple use of viewbinding
- Click the input box to pop up the keyboard layout and move up
- Wechat video extraction and receiving file path
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- Usage of functions decode() and replace() in SQL
- How about CICC wealth? Is it safe to open an account up there
- Esp01s with Arduino development environment
猜你喜欢
Introduction to ROS learning notes (I)
JVM的类加载过程
C: generic reflection
ctfshow-web361(SSTI)
os_ authent_ Prefix
ESP32 LVGL8. 1 - roller rolling (roller 24)
Esp32 (UART ecoh) - serial port echo worm learning (2)
Druid SQL和Security在美团点评的实践
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
8266 obtain 18b20 temperature
随机推荐
Methods of nested recycleview to solve sliding conflict and incomplete item display
ESP32 LVGL8. 1 - textarea text area (textarea 26)
Nacos集群搭建和mysql持久化配置
ESP32 LVGL8. 1 - img picture (IMG 20)
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
机器学习理论基础篇--关于机器学习的一些术语
2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
ESP32 LVGL8. 1 - roller rolling (roller 24)
The type initializer for ‘Gdip‘ threw an exception
Screen right-click menu in souI
Simple use of navigation in jetpack
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
12个例子夯实promise基础
[mathematical modeling] - analytic hierarchy process (AHP)
12 examples to consolidate promise Foundation
Wechat video extraction and receiving file path
【科普】CRC校验(一)什么是CRC校验?
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Redis common interview questions