Java中静态变量和全局变量之间的区别 [英] Difference between static and global variable in Java

查看:1438
本文介绍了Java中静态变量和全局变量之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java编程的新手。任何人都能说出Java中全局变量和局部变量之间的区别吗?

I am new to Java programming. Can anyone tell what is the difference between global and local variable in Java?

推荐答案

你提到的问题有点困惑标题中的static / global,以及问题中的global / local。

Your question is a little confused since you refer to static/global in the title, and global/local in your question.

static 变量绑定到 class ,每个类你将有一个实例

static variables are tied to a class, and you will have one instance per class.

类可以有成员变量,你将拥有该类的每个实例一个实例。

classes can have member variables, and you will have one instance per instance of that class.

请注意,如果您有多个类加载器,这会更复杂。在这种情况下,您可以加载多个类定义,因此可能有多个静态变量。

Note that this is complicated further if you have multiple classloaders. In this scenario you can have multiple class definitions loaded, and consequently, possible multiple static variables.

这篇关于Java中静态变量和全局变量之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆