import java.util.Date;
import java.text.SimpleDateFormat;
class Test
{
public static void main(String args[])
{
Date d;
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
try{
d=sdf.parse("20-12-2016",0);
}
catch(Exception ex)
{
ex.printStackTrace();
}
System.out.println(d);
}
}
When I compile this code I get
error: variable d might not have been initialized in
System.out.println(d);
but I have assigned it a date using parse function in
d=sdf.parse("20-12-2016",0);