Java: Why am I required to initialize a primitive local variable?

前端 未结 5 1796
自闭症患者
自闭症患者 2020-11-27 06:25
public class Foo {
    public static void main(String[] args) {
        float f;
        System.out.println(f);
    }
}

The print statement causes

5条回答
  •  渐次进展
    2020-11-27 07:09

    Actually local variables are stored in stack.Hence there is a chance of taking any old value present for the local variable.It is a big challenge for security reason..Hence java says you have to initialise a local varible before use.

提交回复
热议问题