1.构造函数不能被继承,只能被显式或隐式的调用
2.
public class Test { static int x = 10; static { x += 5; } public static void main(String[] args) { System.out.println("x=" + x); } static { x /= 3; } ; }
答案:x=5
class A { static { System.out.println("父类静态代码块"); } public A() { System.out.println("父类构造方法"); } { System.out.println("父类初始化块"); } } public class B extends A { static { System.out.println("子类静态代码块"); } public B() { System.out.println("子类构造方法"); } { System.out.println("子类初始化块"); } public static void main(String[] args) { new B(); } }
顺序:父类静态代码块-->子类静态代码块-->父类普通代码块-->父类构造方法-->子类代码块-->子类构造方法;
3.
public class Test { public static void main(String[] args) { double d1 = -0.5; System.out.println("Ceil d1=" + Math.ceil(d1)); System.out.println("floor d1=" + Math.floor(d1)); } }
答案:
Ceil d1=-0.0
floor d1=-1.0
解析:
floor 返回不大于的最大整数
round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(11.5)的结果为12,Math.round(-11.5)的结果为-11。
ceil 则是不小于他的最小整数
符号不变,类型不变