http://www.verejava.com/?id=16992774752140
/** 知识点: static 关键字 1. static 的使用 2. static 变量的内存分配 3. static 的使用限制 4. 主方法 main 的剖析*/public class TestStatic { public static void main(String[] args) { //实例化一个用户 User user1 = new User("xiongmao"); User.count++; System.out.println("实例化用户总数 : " + User.count); //实例化第二个用户 User user2 = new User("tanglang"); User.count++; System.out.println("实例化用户总数 :" + User.count); }}class User { private String username;//用户名 public static int count;//计数器 public User(String username) { this.username = username; }}/** 总结 普通变量和static静态变量的区别 1. 普通变量是运行期动态赋的值 static 变量是在 编译期 就赋给了初始值 2. 普通变量必须通过实例对象引用访问 static 变量可以直接通过类名访问 3. 普通变量存在 堆和栈中 static 变量存在全局代码区中 是共享的*/ 继续阅读与本文标签相同的文章
上一篇 :
搭建本地yum源
下一篇 :
Java 面向对象 之 对象引用 this的引用
-
Apache Solr最新RCE漏洞分析
2026-05-27栏目: 教程
-
以后程序员是否会被人工智能给代替?
2026-05-27栏目: 教程
-
百度CEO李彦宏称如果google回到中国,有信心再赢一次,有这种可能嘛?
2026-05-27栏目: 教程
-
23岁学编程太迟?都这把年纪了,别瞎折腾了
2026-05-27栏目: 教程
-
8月8日云栖精选夜读 | 阿里资深技术专家林轩:云时代软件研发的终局猜想
2026-05-27栏目: 教程
