|
da b = new de (); ---------------- show ba.show
why?
I understand it this way:
1. Method belongs to class
2. Objects access methods through classes
3. There is a reference table for all methods in each class + virtual, parent method reference table for the parent class
4. If the method reference is not found in its own method table, it will go to the parent class to find
5.new keyword will create a new method in the subclass method table
6.The keyword of override will overwrite the parent virtual, abstract method table to point to the methods in the child class (even if the parent class is accessed, the method in the child class is accessed)
7. The reference of the parent object can point to the child object, but the method table of the parent class is used
ba b = new de ();
The method table we use is the method table of ba, then the method found is the method ba.show in ba
same:
If virtual show in ba, new show () in de --------------------- ba.show ()
If virtual show in ba, override show () in de ----------------- de.show ()
If show in ba, new show () in ------------------------------ ba.show () (our kind Happening)
If show in ba, override show () in de ------------------------- Compile fails
------------------------------------------- In confusion of thinking, the master is correcting- -------- -_- "---- |
|