Construction method
The name of the constructor of the class with the same name
No return value can not write void
If you do not write constructor, the default constructor without parameter to generate a
If there is to write a reference or a constructor with no arguments, it will not generate a default constructor with no arguments
. 1 class A { 2 public int I; // I herein is not in vivo, are members of the variables (attributes), 3 // can not initialize, defaults to numeric type 0 . 4 public boolean In Flag; // if boolean type, default to false . 5 . 6 public void Show () { . 7 System.out.printf ( "% D", i); // this case, although there is no assignment to the i, but the output will be 0 . 8 System.out.printf ( "% B ", In Flag); // Boolean type output B% b or% . 9 } 10 } . 11 12 is class const { 13 is public static void main (String [] args) { 14 A AA = new new A (); 15 aa.show (); // call to show method, outputs 0 16 . 17 int K; // here K is in vivo, belongs local variables, initialization is not being given 18 is // Java requires all local variables must be initialized before use . 19 System.out.printf ( "% D", K); // compiler given 20 } 21 }
Overloaded methods
The method of the same name parameter to do similar things in different shape, which is called method overloading
Method overloading Requirements:
- Method shape parameter number
- Parameter sequential method
- Method according to the type of shape parameter
At least one of these three is not the same
If the two methods just return value method (return value type) are not the same, other are the same, which constitute overloaded methods, because they can not determine which method to call the method call, it will be a compile-time error!