C# sealed vs Java final

前端 未结 3 1403
滥情空心
滥情空心 2020-12-24 09:39

Would anybody please tell me as the reason the following use of sealed does not compile? Whereas, if I replace sealed with final and c

3条回答
  •  醉酒成梦
    2020-12-24 10:09

    Sealed in C# can be applied only to a reference types, and has impact on inheritance tree.

    In practise the type marked as sealed guranteed to be the last "leaf" in the inheritance tree, or in short, you can not derive from the type declared like a sealed.

    public sealed class Child : Base 
    {
    }
    
    public class AnotherAgain : Child //THIS IS NOT ALLOWED
    {
    }
    

    It can not be applied to a members.

提交回复
热议问题