1

I have read how local variables are not set to default values to not have undefined behavior and if an error happens we know that, we did not initialize the value of the local variable inside the that local scope block of code. However, what was the reasoning behind to have default values set for instance variables in Java? How is the Java compiler not smart enough to know if instance fields are not initialized but is smart enough for local variables in Java? What was the reason for this decision? The answer on this site is about before Java 7 or up to 7, since it is Java 14 now I wonder if things have changed or not.

belled
  • 11
  • 2

0 Answers0