Java Interview Question

Use this basic question and answer to prepare for your next Java interview.

What happens if you use a primitive local variable before initializing it?


The Java compiler will throw an error. Local variables do not get initialized to any default value even if they are primitives like int or boolean. Every local variable needs to be assigned a value before it can be accessed.

Looking for developers?

Want to learn more about Gigster? Enter your email and one of our project engineers will be in touch.