Why are local variables not initialized in Java?

后端 未结 15 934
不知归路
不知归路 2020-11-22 09:28

Was there any reason why the designers of Java felt that local variables should not be given a default value? Seriously, if instance variables can be given a default value,

15条回答
  •  执念已碎
    2020-11-22 09:42

    The answer is instance variables can be initialized in class constructor or any class method, But in case of local variables, once you defined whatever in the method that remains forever in the class.

提交回复
热议问题