Block: a code in brackets
When the object configuration code block operation, performed before construction method, in which method the temporary write block after the letter sequence with related
Static code block: static code block will be executed when the class is loaded, so static code block is executed only once, ordinary block of code is executed at the time of construction objects, each object has a
Interface (interface): abstract methods defined specifically regulate
Interface attributes: will be invisible plus public static final, but can not be added to this conflict, and this property must be initialized
Interface methods : 1. Must all abstract methods, default at public abstract
All the abstract methods 2. If we are to implement an interface must implement this interface, unless the class is an abstract class
3. The interface can not be instantiated directly, that can not be used in conjunction with the new keyword
4.java inside the class can not multiple inheritance, but more than a few mouthfuls can inherit
5. After 1.8, you can also define a static non-abstract methods in an abstract class
Interface can be used as markers: such as AB inherit C, but did not inherit C D
We can use A instanceof C, to separate the ABD
The target pressing certain requirements sorted order: this type must be comparable
// definition of the initial value assigned to the array and Person
Person [] PS = new new Person [ . 5 ]; PS [ 0 ] = new new Person ( " John Doe " , 42 is ); PS [ . 1 ] = new new Person ( " Joe Smith " , 22 is ); PS [ 2 ] = new new the Person ( " bachelor " , 32 ); PS [ . 3 ] = new new the Person ( " Tommy star " , 52 ); PS [. 4 ] = new new the Person ( " Li Huayu " , 62 );
// call to the sorting method Arrays.sort Arrays.sort (PS); for (the Person A: PS) { . The System OUT .println (A); }
// by last name hours override compareTo method @Override public int compareTo (the Person O) { return - the this .getName () compareTo (o.getName ());. }