1. Rewrite <override> and reload <overloading>
Rewriting is a manifestation of Java polymorphism relative to the parent class and the overload is relative to the current class.
2. Java internal class
At the beginning, there is no need to elaborate on every function. The top-down list is as follows:
<1> internal class definition: as the name suggests, the class defined inside the class is an internal class.
<2> simple examples of internal classes:
public class OutClass(){ public class InsideClass() {
... }}
<3> use of internal classes: (using an internal class to access external class member variables)
Public class Test2 {
Private int num; Public Test2 () {} public Test2 (INT num) {This. num = num;} private class inner {public Test2 gettest2 () {return test2.this;} public Test2 newtest2 () {return New Test2 ();}} public static void main (string [] ARGs) {Test2 test = new Test2 (5); test2.inner inner = test. new inner (); Test2 Test2 = inner. gettest2 (); Test2 test3 = inner. newtest2 (); system. out. println (test2.num); system. out. println (test3.num );}
}
Output result: 5 0
Explanation: As long as an internal class object is created through an external class, the internal class is associated with the external class, and the external class member variables and methods can be accessed without restrictions.
Use the following method: External class. This;
Principle: When an external class creates an internal class object, the internal class will secretly capture a reference pointing to the external class. The specific mechanism is a compiler problem and it is not necessary to go into details at the beginning.
<4> encapsulation and hiding of internal classes:
Public class example {private class insideclass implements interfacetest {public void test () {system. out. println ("this is test") ;}} public interfacetest getin () {return New insideclass ();}}
// Test the public class testexample {public static void main (string ARGs []) {Example A = new example (); interfacetest a1 =. getin (); a1.test ();}}
Explanation: Obviously, the interfacetest () method of the example class returns an insideclass object, and the insideclass is private. If we do not take the code seriously
We cannot see the specific implementation of insideclass. This backup seems to be relatively high-end.
OK, that's it!