Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does C# not use the same default of non-inheritable classes? Or is it just at the method level, where you have to mark methods as overridable?


Classes in C# are inheritable by default, as in Java, but can be marked sealed (final). Members (methods and properties) in C# are final by default, and must be explicitly marked virtual.


For what it's worth, Jon Skeet of StackOverflow fame and C# fanaticism, thinks C# classes should also be sealed by default.

"I'd say it was just a mistake. I know many people (including myself) who believe that classes should indeed be sealed by default. There are at least a couple of people in the C# design team in that camp. The pendulum has swung somewhat away from inheritance since C# was first designed. (It has its place, of course, but I find myself using it relatively rarely.)"


Ah, that's where I got confused, I remembered there was something in C# which made classes not-really-inheritable by default but had no way to test it.


You have to mark methods as virtual - I believe classes are by default.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: