#Things you may want to know about Constants and Readonly

constants (const): The value of const is set at compile time(the value must be set when you declare it) and cannot  be changed at run time.

ReadOnly : They need not be initialized  when declared ,but must be initialized in constructor. They could be initialized else where other than constructor.

  1. const are themselves static, so you cannot declare
     public static const int s =1 --Error cannot be static

2 .const can be used only with primitive types(exception is Strings) .i.e it does not make sense to use custom class with const.

 public cosnt myclass = new myclass() ---Error must be a compile time value 


Its possible for you to do that with ReadOnly.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s