当前位置:网站首页>About abstact and virtual

About abstact and virtual

2022-06-26 05:29:00 Elliot_ Alderson

        Study in school C# When , I often skip classes , In addition, the teacher didn't attract my attention very much at that time , For abstract classes abstract and virtual Virtual methods and other things are always not understood , Fortunately, I didn't get much in the final exam .

        In a brief summary :

       abstract You can declare abstract classes and abstract methods .

        Abstract methods can only be declared in abstract classes , And once declared as an abstract method , It cannot be implemented at the time of declaration .

        Once an abstract method subclass inherits , Must be realized , Otherwise, it will violate the rules .

       virtual Virtual methods can be declared .

        Virtual methods can be declared in any class , It can be implemented at the declaration place , And virtual methods cannot be declared as private.

        Subclasses can choose whether to override virtual methods or not .

        To put it bluntly ,abstract The abstract method of is equal to a necessary condition , If you inherit it, you must do it , and virtual Equal to the optional condition , It doesn't matter whether you do it or not .

OvO

原网站

版权声明
本文为[Elliot_ Alderson]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180506068980.html