用户登录
用户注册

分享至

基元的默认值

  • 作者: 珏男
  • 来源: 51数据库
  • 2022-11-14

问题描述

在 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.

阅读主题这里.

软件
前端设计
程序设计
Java相关