I tried doing something of declaring a static blind final variable and tried to initialize it in the static block. Problem is my initilialization theows a checked exception. Now im trying to catch using try catch block but it gives problem.
Is there any way this can be done in
java.
class A {
public static final
String out;
// they cant initialize out here because calling the constructor //of printstream will cause an exception
// now they can put it in a static block but unfortunately this //code gives an unitialized error thatz valid because what if an //exception occurs
/* static {
try{
out = "string";
}catch(Exception e){}
} */
//now i tried this we cant use this also i dont know why
static {
try{
out = "string";
}catch(Exception e){out = "string";}
}
}
even this gives error but why when im initializing the final variable in all cases ie, if an exception occurs and also in the normal flow.
Cherry