5.1. Inheritance

Inheritance allows a class to extend and reuse behavior defined in its ancestor class (superclass). Java and C# support only single class inheritance, in which a given class can inherit from only one other class. This is in contrast to C++, which allows a class to inherit behavior from multiple classes.

Inheritance creates an is-a relationship between the subclass and the superclass; in other words, a subclass is a type of the superclass. Because of the single class inheritance in Java and C#, you must be careful in choosing which class to inherit your class from. For example, if you have a custom maplike data structure, should you inherit from java.util.HashMap? Doing so would instantly make your data structure a java.util.HashMap ...

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.