Features of Read only variables
-
It is allocated at compile time
-
Declaration and initialization is separated
-
It is allocated at runtime
-
all of these
Read-only variables (const, readonly) are allocated at runtime in .NET, unlike compile-time constants. Option A is incorrect because compile-time allocation is for constants (const), not readonly fields. Option B is incorrect - readonly variables can be declared and initialized separately (declaration at field, initialization in constructor). Option D is false since the other options contradict each other and cannot all be true.
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) It is allocated at compile time - This option is incorrect. Read-only variables are not necessarily allocated at compile time. The allocation of memory for read-only variables can happen at either compile time or runtime, depending on the programming language and the specific implementation.
Option B) Declaration and initialization is separated - This option is incorrect. The separation of declaration and initialization is not a specific feature of read-only variables. It depends on the programming language and the specific syntax rules.
Option C) It is allocated at runtime - This option is correct. One of the features of read-only variables is that they can be allocated at runtime. This means that the memory for read-only variables is allocated during the execution of the program, rather than at compile time.
Option D) All of these - This option is incorrect. Only option C is correct. Options A and B are incorrect.
The correct answer is C) It is allocated at runtime. This option is correct because read-only variables can be allocated at runtime.