Which statement is invalid with regards to Constant

A) They must be initialized when they are declared
B) The value of the constant must be computable at compile time
C) Constants are not static
D) Constant is a variable whose value can be changed through out it’s life time when it is static.

Showing Answers 1 - 29 of 29 Answers

vasu253

  • Dec 18th, 2007
 

if we declare a variable as constant, the value of the variable will be same throughout the application, and the answer is A.

  Was this answer useful?  Yes

Sanjida123

  • Jun 4th, 2010
 

Constant is compile time initialization. It means at the time of constant declaration programmer has to initialize the value for it and this value won't be changed once it is initialized. Implictily compiler treats constant as static.

So, answer D is invalid.

  Was this answer useful?  Yes

levteck

  • Aug 16th, 2010
 

straight out of MSDN:

"The static modifier is not allowed in a constant declaration."

The invalid statement is d)

  Was this answer useful?  Yes

Elean0r

  • May 25th, 2011
 

Statement D is definitely invalid.

Statement C occupies a grey area, since:
a) a const field will have the same value in each object of that class; so it appears to  have same effect as a static readonly, and hence it is sometimes described as implicitly static;
 however,
b) the value of a const must be known at compile whereas a static readonly can be initialized at runtime, via a constructor.
 and as other contributors have pointed out,
c) the "static" qualifier may not be applied to a const.

So strictly , only D is invalid

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions