I have Java two programs.
Program One
class Ideone
{
public static void main (String[] args)
{
double price = 10;
String model;
if (price > 10)
model = "Smartphone";
else if (price <= 10)
model = "landline";
System.out.println(model);
}
}
Output :- variable model might not have been initialized(Error)
Program Two:-
class Ideone
{
public static void main (String[] args)
{
double area = 10.98;
String color;
if (area < 5)
color = "red";
else
color = "blue";
System.out.println(color);
}
}
Output:- blue
My question here is since both the programs are almost similar, why am I getting variable might not have been initialized ?
If the first program is having the problem, should not the 2nd program also throw the same error ?