类属性不能写在try{}catch(){}里面

public class cal{
public static void main(String[] args){
calculator ca=new calculator();
byte[] first=new byte[4];byte[] second=new byte[4];
System.out.println("请输入first");
try{
System.in.read(first);
}
catch(Exception e){e.toString();}
String f=new String(first);
System.out.println("请输入second");
try{
System.in.read(second);
}
catch(Exception e){e.toString();}
String s=new String(second);

System.out.print(f+","+s);

}
}

类属性不能写在try{}catch(){}里面,里面的只是临时的,try块结束就没有了,比如f和s要在try{}catch(){}外面定义才能打印

原文地址:https://www.cnblogs.com/heysong/p/3703718.html