New VS Virtual + Override

xiaoxiao2021-03-06  18

In C #, the function is not virtual, but it can be clearly declared that the virtual (except for constructor), in Java, all functions are virtual based on what?

If the base class function is not declared as a Virtual, the same method is used in the inheritance class, and the NEW keyword must be declared with the new keyword, otherwise there is a warning (final effect is not different), which is hidden by the base class method. If the base class function is declared as Virtual, inheritance class is the same as the base class, you must declare the Override keyword, which is the so-called rewrite.

The difference between the hidden and rewriting is: hidden, if you point to the instance of the inherited class with a base class, the method of the object is characterized by a base class, not the example itself, that is, the method of call which class is depends on the reference instance Variable type; rewrite, if the reference to the inheritance class with a reference reference, the method of calling which class is dependent on the instance itself.

转载请注明原文地址:https://www.9cbs.com/read-46060.html

New Post(0)