A, static static modifier
1 is a modifier of our main function, but marked to be modified static class members can be called directly, such as the type of property :( |.. Name of the class method)
2, static modifier mainly used in five places:
* Static member variables
* Static member method
* Static code block
* Static inner classes
* Static guide package
3, static and non-static difference
A difference: static member is modified with load and load class (priority), rather than static members, with the creation of objects and loads
Difference between the two: the static method | static code block can only call a static member, non-static member can not be called directly, create an object (you can not use this keyword)
non-static method can call non-static member directly, you can call a static member of the class. the object is to call the static member
Three differences: a static member for more than one object is shared
non-static member for multiple objects are independent of each other
Second, the package type
1, the public class property definitions are encapsulated in the internal process called: properties and methods comprising
2, in order to ensure the privacy field: we chose to use the private modifier modifying variables
3, the statement corresponding to the get / set of read and write operations to support variable
frame subsequent learning recognize only get generated shortcut alt MyEclipse SET in the get / set R + shift + s click to select the corresponding field generating get / set
Third, the variable length parameters
1, the format is: type ... parameter name (eg: String ... name)
2, variable length parameters must be written at the end of the parameter list, and variable length parameters can be only one
3, is a variable length parameter substantially parameters into an array of respective lengths;
. 1 public class lianxi { 2 public static void main (String [] args) { . 3 print (1,2,3,4,5,6 ); // call the print method, six parameters . 4 System.out.println ( ); . 5 print (1,2,3,4,5,6,7,8,9 ); // call the print method, nine parameters . 6 } . 7 . 8 public static void print ( int ... A) { // parameters are variable length parameter . 9 for ( int I: A) { 10 of System.out.print (I + "" ); . 11 } 12 } 13 }
Fourth, the method overloading
1, a method to ensure that different parameters of the same name: Type number sequence
2, and independent access modifier return value type
Fifth, recursive functions
1, characterized in that: calls itself
2, the focus is: to determine when the end of recursive
Recursion examples
. 1 public class Feibonaqie { 2 // value of the n number of items that the cut output value Fibonacci column . 3 static int feibonaqie ( int n) { . 4 IF (n ==. 1) return 0 ; . 5 IF (n == 2 ) return . 1 ; . 6 return feibonaqie (. 1-n-) feibonaqie + (2-n- ); . 7 }
. 1 public class to Test01 { 2 public static void main (String [] args) { . 3 Scanner INPUT = new new Scanner (the System.in); . 4 System.out.println ( "Please enter the number you want to output the front cut Fibonacci number column item: " ); . 5 int n-= input.nextInt (); . 6 // use recursion . 7 of System.out.print (" cut before Fibonacci number column "+ n +" key is: " ); . 8 for ( int I . 1 =; <= n-I; I ++ ) { . 9 of System.out.print (Feibonaqie.feibonaqie (I) + "" ); 10 } . 11 }
The following examples present a schematic diagram of the recursive