5.7. Summary

Inheritance is a powerful concept and should be used whenever appropriate. However, you should design class hierarchies with caution because C# allows you to extend only one class. Prefer composition over inheritance because composition allows for greater flexibility in switching your actual implementation and insulating the end users of your class from changes to the class's internals.

Here are the key concepts you should take away from this chapter:

  • In C#, methods are nonvirtual by default. In Java, all methods are virtual by default. This means that in C#, virtual dispatching is not automatically turned on; therefore, method calls are always made on the reference instead of the object instantiated. To achieve Java-like virtual ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.