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

前端 未结 5 1798
自闭症患者
自闭症患者 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 06:57

    Hi guys solution is simple. the values that are stored on the heap memory are initialized by the compiler based datatype but local variables are stored on stack memory so we have to inialize it explictly.

提交回复
热议问题