In: Computer Science
Which of the following statements is NOT correct?
A. It is allowed to declare a variable and initialize it in one statement.
B. Once a variable is declared and initialized, you can change its value later on.
C. The variable declaration tells the compiler to allocate appropriate memory space for the variable based on its data type.
D. It is allowed to declare two variables with the same name but with different data type.
Ans:
A. It is allowed to declare a variable and initialize it in one statement
Variables reserve data in memory that is handled by the program. Variables can store strings of lines and numbers.
While you declare a variable, you should also initialize it. Two kinds of variable initialization survive: explicit and implicit. Variables are explicitly initialized if they are allocated a value in the declaration statement. Implicit initialization occurs when variables are allocated a value during processing.
This data covers criteria for declaring and initializing variables in functions and adds a model of conventional forms.
Use this format when declaring and initializing variables:
Declare variables using this setup:
datatype var name = initial value; /* comment*/
so the answer is Yes
B. Once a variable is declared and initialized, you can change its value later on
They are linked with the class, rather than with an object. Every instance of the class shares a class variable, which is in one set location in memory. Any object can change the utility of a class variable, but class variables can also be manipulated without creating an instance of the class.
so yes you can change its value later on.
C. The variable declaration tells the compiler to allocate appropriate memory space for the variable based on its data type.
The quantity of memory location to be allotted for a variable is originated by modifiers. Modifiers are prefixed with basic data types to modify (either increase or decrease) the quantity of storage allocated to a variable.
so the answer is yes
D. It is allowed to declare two variables with the same name but with different data types.
You can not have variables having the same name [but different types ] to survive in the same scope.
The java compiler can not recognize which var you are really referring to. So such a code is not syntactically accurate and not compilable.
so this statement is NOT correct.
please do not forget to give a thumbs up.
have a nice day!!