Here is an example of this error :
public class VariableMightNotHaveBeenInitialized
{
public static void main(String args[])
{
int a,b,c;
a=10;
c=a+b;
System.out.println("The sum is "+c);
}
}
Here variable ‘b’ is added with variable ‘a’ before assigning any value.
Correct code is:
public class VariableMightNotHaveBeenInitializedSolution
{
public static void main(String args[])
{
int a,b,c;
a=10;
b=20;
c=a+b;
System.out.println("The sum is "+c);
}
}
0 comments:
Post a Comment