Question:

"Variables in Java need not be declared and initialized before they are used." State True or False.

Show Hint

In Java, always declare and initialize variables before using them to avoid compile-time errors.
Updated On: Jul 14, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

In Java, all variables must be declared before they are used.
Declaration means specifying the data type and the name of the variable.
For example: int num; declares an integer variable named num.
If a variable is used without declaration, the Java compiler will throw a compilation error.
Also, local variables in Java must be explicitly initialized before use; otherwise, the code will not compile.
Java is a statically-typed language, meaning it checks variable types during compilation, unlike dynamically-typed languages such as Python.
Therefore, the statement given in the question is False.
Was this answer helpful?
0
0

Questions Asked in CBSE CLASS XII exam

View More Questions