public class Test1 {
public static void main(String[] args) {
int a = 10;
System.out.println(test2(a));
}
public static int test2(int b)
{
try {
b += 10 ;
return b;
} catch (RuntimeException e){
}
catch (Exception e2) {
}
finally {
b += 10;
return b;
}
}
}
/*
* 关于try catch 知识: 程序运行到try块, b = 20; 并没有发生异常,不运行catch块, 运行到return b;
* 因为finally无论如何都要运行该,因此,并不发生返回动作, 进而运行finally块, b = 30 进行程序返回输出。
*/
public class Test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
byte b1 = 4;
byte b2 = 10;
byte b3 ,b4 ;
final byte b5 = 1, b6 = 2;
b3 = b5 + b6;
//b4 = b1 + b2; 两个byte 相加的默认值是int,而int 不可以给byte 直接赋值
}
}
public static void main(String[] args) {
String s = null;
/*if(s!= null & (s.length()>0)) //会抛出异常
{
}*/
/*if(s!= null && (s.length()>0)) //不会
{
}*/
/*if(s == null | s.length() == 0) //会抛出异常
{
}*/
/*if(s== null || (s.length() == 0)) //不会
{
}*/
if(s!= null){}
}
}
/**
* 此题主要考察的是 位运算符 & | ! 和逻辑运算符的使用 规则:
* 位运算符的左右两侧不管是真是假,都会执行;
* 逻辑运算符则不一样, 如果左侧是假,则&& 的右侧不再执行操作运算,结果是假;
* 同理,|| 的左侧是真,则其右侧不再执行,结果肯定是真;
*
* 此题的要点在于: 入过执行 s.length() 肯定会抛出空指针异常。所以,看题中哪些选项执行了s.length
*
*
*/