答:会。checked exception是必检异常,经过编译器验证。对于声明抛出异常的任何方法,编译器将强制处理或声明规则。unchecked exception是免检异常,如RuntimeException。它是运行时异常。因为此类异常通常由特定操作引发,这些操作在内存中经常出现。Thread.sleep()抛出InterruptedException异常,属于checked exception。
答:(double)-9.0。Math.floor():不大于该数的最大整数,返回double类型。Math.round():返回int,四舍五入,算法为Math.floor(x+0.5),表示原来的数加上0.5向下取整。Math.round(-11.5)的结果为:-11
public class TestDemo {
public static String output ="";
public static void foo(int i){
try{
if(i == 1){
throw new Exception();
}
}catch(Exception e){
output += "2";
return ;
}finally{
output += "3";
}
output += "4";
}
public static void main(String[] args) {
foo(0);
foo(1);
System.out.println(output);
}
}
答:3423。try-catch执行结束后,程序继续向下执行。throw new Exception(),发生了异常,程序执行完finally块后,就结束。
public class HelloB extends HelloA
{
public HelloB()
{
}
{
System.out.println("I’m B class");
}
static
{
System.out.println("static B");
}
public static void main(String[] args)
{
new HelloB();
}
}
class HelloA
{
public HelloA()
{
}
{
System.out.println("I’m A class");
}
static
{
System.out.println("static A");
}
}
答:
static A static B I’m A class I’m B class
该题主要考察了java的执行顺序。父类静态块--子类静态块--父类块--父类构造器--子类块--子类构造器
参考http://java-mzd.iteye.com/blog/838683
类方法不可以用this来调用;在类方法中调用本类的类方法可以直接调用;在类方法中可以调用其他类的类方法;在类方法中可以调用实例方法
类方法是静态方法,this是调用当前对象的属性和方法。所以不能用this调用类方法。
原文:http://www.cnblogs.com/ckui/p/5998780.html