Would anybody please tell me as the reason the following use of sealed
does not compile? Whereas, if I replace sealed
with final
and compile it as Java, it works.
private sealed int compInt = 100;
public bool check(int someInt)
{
if (someInt > compInt)
{
return true;
}
return false;
}
That's because final
in Java means plenty of different things depending on where you use it whereas sealed
in C# applies only to classes and inherited virtual members (methods, properties, events).
In Java final
can be applied to:
sealed
.virtual
and in a derived class this can be prevented for further derived classes with sealed
again. That's why you see sealed
members in C# a lot less than final
members in Java.readonly
.