If a variable in Java is not assigned, the member variable is initialized by default and the local variable does not.
For member variables int A; The initial value of a is 0
The member variables in the following example A,b,c,d
public class Variableinitialvalue {public static void main (String args[]) {testvariable obj = new testvariable (); System.out.println ("a=" +obj.a); System.out.println ("b=" +obj.b); System.out.println ("c=" +obj.c); System.out.println ("d=" +OBJ.D);} Class TestVariable {int A;char b;float C; String D;}
The output is:
For the local variable int A; A default is not initialized
The Java compiler will give you an error warning if you are manipulating variables that are not initialized.
The local variable, a, B in the following example
public class Variabledeclaration {public static void main (String args[]) {System.out.println ("Examples of variable Declar ation "); int A; System.out.println ("a=" +a); String b; System.out.println (b);}}
Error message:
The local variable a May is not having been initialized
The local variable B may not have been initialized
The initial value of the Java variable