当前位置:网站首页>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
边栏推荐
- Go language GUI framework Fyne Chinese garbled or not displayed
- The difference between ordinary inner class and static inner class
- Feature selection feature_ selection--SelectKBest
- How about CICC wealth? Is it safe to open an account up there
- Raspberry pie uses root operation, and the graphical interface uses its own file manager
- Screenshot using projectmediamanager
- Sogou cell thesaurus analysis (only extract words and word frequency)
- c#:泛型反射
- ESP32 LVGL8. 1 - calendar (calendar 25)
- JVM的类加载过程
猜你喜欢
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
ESP32 LVGL8. 1 - arc (arc 19)
MySQL学习第五弹——事务及其操作特性详解
Introduction to ROS learning notes (II)
Getting started with vcpkg
Some records used by VS2010
mysql_linux版本的下载及安装详解
ESP32 LVGL8. 1 - input devices (input devices 18)
Druid SQL和Security在美团点评的实践
12 examples to consolidate promise Foundation
随机推荐
Simple use of viewbinding
Teach you to quickly rename folder names in a few simple steps
Scrollto and scrollby
Fundamentals of machine learning theory -- some terms about machine learning
Using 8266 as serial port debugging tool
Advanced transfer learning
Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Implementation of TCP UDP communication with golang language
使用晨曦记账本,分析某个时间段每个账户收支结余
[popular science] CRC verification (I) what is CRC verification?
Sentinel规则持久化进Nacos
Esp32 (UART 485 communication) - 485 communication of serial port (3)
Screenshot using projectmediamanager
Practice of Druid SQL and security in meituan review
关于unity文件读取的操作(一)
How about CICC wealth? Is it safe to open an account up there
Circuit on-line simulation
How can programmers quickly develop high-quality code?
Druid SQL和Security在美团点评的实践