基元的默认值

default values for primitives(基元的默认值)

本文介绍了基元的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中,如果 int 类型的变量没有被初始化,它会保存什么(我知道如果我在初始化之前直接使用 x 它不会让我编译)?

In Java, what would a variable of type int hold if it was not initialized (I know that it will not let me compile if I used x directly before initializing)?

说,如果我这样做了:

int x;

怎么样

int[] x;

谢谢

推荐答案

实例变量将被默认为一个合理"的值.局部变量将包含垃圾.

Instance variables will be defaulted to a 'reasonable' value. Local variables will contain garbage.

阅读主题这里.

这篇关于基元的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:基元的默认值