Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it possible to declare a variable without an initial value?

Tags:

People also ask

Is it possible to declare a variable without initial value in Java?

Yes, it is. The author of the book mentions that this feature is valid in Java, I'll edit the post. Good question.

Can you declare a variable without initializing?

If you declare a final variable later on you cannot modify or, assign values to it. Moreover, like instance variables, final variables will not be initialized with default values.

Can you declare a variable without a value?

Still, this is a common question asked by many programmers that can we declare any variable without any value? The answer is: "Yes! We can declare such type of variable". To declare a variable without any variable, just assign None.

What happens if you do not assign an initial value to a variable?

An uninitialized variable is a variable that has not been given a value by the program (generally through initialization or assignment). Using the value stored in an uninitialized variable will result in undefined behavior.


I'm reading Gilles Dowek's Principles of Programming Languanges:

He says that it's also possible to declare a variable without giving it an initial value and also that we must be careful not to use a variable which has been declared without an initial value and that has not been assigned a value. This produces an error.

Note: The book's author mentions the possibility of declaring variables without an initial value on Java.

So, why is this declaration of variables valid? When am I going to use it?