且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java中的本地变量和实例变量之间有什么区别

更新时间:2022-05-08 03:30:26

我能想到的另一件事是:

One extra thing I can think of:

实例变量被赋予默认值,如果是对象引用则为null,如果是int,则为0。

Instance variables are given default values, ie null if it's an object reference, 0 if it's an int.

局部变量没有得到默认值,因此需要显式初始化(​​如果你不这样做,编译器通常会抱怨)。

Local variables don't get default values, and therefore need to be explicitly initialized (and the compiler usually complains if you fail to do this).