首页 > 其他 > 详细

static关键字

时间:2021-08-14 00:08:07      阅读:42      评论:0      收藏:0      [点我收藏+]
 1 public class Test {
 2     //属性:
 3     int id;
 4     static int sid;
 5 
 6     //这是一个main方法,是程序的入口
 7     public static void main(String[] args) {
 8         //创建一个Test类的具体对象
 9         Test t1 = new Test();
10         t1.id = 10;
11         t1.sid = 10;
12 
13         Test t2 = new Test();
14         t2.id = 20;
15         t2.sid = 20;
16 
17         Test t3 = new Test();
18         t3.id = 30;
19         t3.sid = 30;
20 
21         //读取属性的值
22         System.out.println(t1.id);
23         System.out.println(t2.id);
24         System.out.println(t3.id);
25 
26         System.out.println(t1.sid);
27         System.out.println(t2.sid);
28         System.out.println(t3.sid);
29     }
30 }

内存分析:

技术分享图片

 

static关键字

原文:https://www.cnblogs.com/yangkaifei/p/15139017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!