C# sealed vs Java final

前端 未结 3 1409
滥情空心
滥情空心 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 09:57

    Tigran's answer is not wrong while Joey's is a little incorrect.
    Firstly you can look into this page: What is the equivalent of Java's final in C#?.
    the sealed key word can apply to class,instance method and property but not variables, or interface's methods. Classes with sealed cannot be inherited. When sealed put on method, it must be by override in company. Every struct is sealed, so struct cannot be inherited. Check this image: sealed usage

提交回复
热议问题