Local Variable
why is it necessary to initialize local variables before using it?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 25, 2014, 4:51 AM EST
This could lead to some serious and hard to find bugs.
Pratiyush AnandRank #2,423 · 582 reputationPosted Feb 25, 2014, 6:26 AM EST
VulpesRank #55 · 29.2K reputationPosted Feb 25, 2014, 6:33 AM EST
The Java compiler issues an error if you haven't initialized the variable before usage to prevent such a bug from occurring.
Unlike C/C++, Java is a very safe language.