1. Constructors cannot be inherited and can only be called explicitly or implicitly
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; } ; }
Answer: x=5
class A { static { System.out.println("Parent class static code block"); } public A() { System.out.println("Parent class constructor"); } { System.out.println("Parent class initialization block"); } } public class B extends A { static { System.out.println("Subclass static code block"); } public B() { System.out.println("Subclass constructor"); } { System.out.println("Subclass initialization block"); } public static void main(String[] args) { new B(); } }
Sequence: parent class static code block --> child class static code block --> parent class ordinary code block --> parent class construction method --> child class code block --> child class construction method;
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)); } }
Answer:
Ceil d1 = -0.0
floor d1=-1.0
Parse:
floor returns the largest integer not greater than
round is the calculation of 4 rounding to 5. When entering, it is theround method to an integer greater than it. It means "rounding up". The algorithm is Math.floor(x+0.5), which is to add 0.5 to the original number and then go down. Rounding, so the result of Math.round(11.5) is 12 and the result of Math.round(-11.5) is -11.
ceil is the smallest integer not less than him
The symbol does not change, the type does not change