1 virtual

1 differents:

'virtual' just in C#  

In Java It does't have the keyword

2 Usages in C#

         used in base class,two situations as following :

        • If you define one function by 'virtual' in base class,and you don't override this function in derived classes. when it invoked, the function in base class will be call back.

        • If you define one function by 'virtual' in base class,and you do override this function in derived classes. when it invoked, the function in derived class will be call back.

What is virtual function?

This means that it does not  really exist in the Memory until the object will have  been instantiated.

3 Usages in Java

          firstly, there is no keyword of 'virtual'

          In Polymorphism, when the object reference of superclass appoint to the object of superclass, if you want to invoke the functions in subclasses,you must add the '@override' above the fucntions you overrided in the subclasses.

          For you reference, pls see the article named 'Factory Method'.

Aimer,c'est partager
原文地址:https://www.cnblogs.com/pickKnow/p/8446906.html