First, the package
1. Function: Effectively protect the state of the object (that is, the attribute value).
2. External call: Provides the Get/set method for the property.
3. Advantages: Avoid errors and security problems caused by direct data operation, protect the integrity of data and improve the maintainability of the program.
Ii. inheritance
1. Function: Extract the duplicate code into the unified class, through the extends keyword to implement the inheritance relationship.
2. Advantages: Eliminate the duplication of code, facilitate maintainability.
3. Features: Java inheritance is a single inheritance, is the relationship between classes, each subclass can inherit only one parent class.
4. Constructor call rule: The subclass constructor always calls the constructor of the parent class, and when the first row of the subclass constructor has no this or supe () r, the system automatically adds super () to call the parent class without a parameter constructor.
Three, polymorphic
1. Definition: A variety of forms of the same object, when the subclass inherits the parent class, the subclass object has two kinds of forms, one is the original state of the object itself, and the other is the parent of the object is polymorphic.
Explanation: An object of the parent class can point to an object of the child class instance. Parent class parent = new Subclass ();
2. Method overrides (overriding) and method overloads (overloading) are different manifestations of Java polymorphism
1) method overloading is the representation of polymorphism in a class, in order to initialize different parameter values.
2) method overrides are the representation of polymorphism between a parent class and a subclass.
Add:
3. Bubble sort
Thought: Compare adjacent two numbers in turn, place decimals in front, large numbers behind, so repeat until the final sort is finished.
PublicStaticvoid main (string[] args) {int [] ts = {0,3,4,7,1,9,2,5,6,8}; for (int i = 0; i<ts.length; i++ ) {for (int j = i+1; j< Ts.length; J++) {if (Ts[i]>ts[j]) {int i1 = ts[i]; int i2 = Ts[j]; Ts[i] = I1; TS [j] = I2;}} } for (int S:ts) { System.out.print (s); } }
4. Select sort
Idea: Each time you select the smallest element from the data element to be sorted, place it at the end of the row, until the data element is finished.
PublicStaticvoidMain (string[] args) {int [] t = {0,3,4,7,1,9,2,5,6,8};int minindex = 0;Forint i = 0; i<t.length; i++) {minindex = i; For (int j = i+1; j<t.length; j + +) { if (t[minindex]>t[j]) {minindex = j; System.out.println (Minindex); }} if (minindex! = i) { int i1 = T[i]; int i2 = T[minindex]; t[i] = i2; T[minindex] = i1;}} For (int s:t) {System.out.print (s);}}
Java Object-oriented