Sealed keyword in association with override

后端 未结 4 1729
无人共我
无人共我 2021-01-07 19:53

Is it always necessary to follow the sealed keyword with override in the signature of a method like the below code:

public sealed o         


        
4条回答
  •  清酒与你
    2021-01-07 20:16

    I think Mr. Hilgarth has provided the best answer here , but just to add something new for programmers who have a previous background in Java(like myself), I think most programmers new to C#, tend to confuse sealed with final in Java with respect to overriding.

    In Java, the default behaviour without specifying "any" modifier is that the method can be overriden in its derived classes.

    While in C#, the default behaviour is that the method cannot be overriden unless explicitly specified using the virtual keyword.

    Hope this helps to supplement the best answer above.

提交回复
热议问题