public class Test { public static void main ( String[] args) { int value; value = value + 1; System.out.println(" The value is : " + value); } } Here compiler is saying not have initialize the value of "value". But what I know is that compiler default initialize it to its type value as it is integer so it would be 0. Please comment thanks in advance
Hi Payal, Default initialization takes place only for member variables (static or instance). Your "value" is a local variable. Local variables has to be initialized by the programer. The only default initialization in local scope I know is that Array e l e m e n t s (not the array itself) are initialized to default values (0, false or null) in local scope (after initializing the array (example: String ar[] = ar[2]), too. correct me if I am wrong Axel
Hi, The variables which intializes by default are declare in class.That is either as a class variables or instance variables.In your case you have declare value in main method. Regards, Hassan
Hi payal, local variables, those declared in methods or blocks of code must be definitely assigned a value before you attempt to use them. As others have pointed out, they are not set to any default value. (See the JLS Chapter 16). Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform