6.4. Looking at System.Object

Here's something that makes C# look more like Java than its official ancestor C++.

Like Java

  • Only single class inheritance is supported in C#. A C# class can implement multiple interfaces. [5]

    [5] C++ supports multiple class inheritance and does not support interfaces.

  • All Java classes are implicitly subclasses of java.lang.Object. In C#, all classes are implicitly subclasses of System.Object. [6] This implies that all C# classes must have one, and only one direct superclass, except for System.Object.

    [6] There are several advantages of having all your classes share a common ancestry. At the very least, you are assured that whatever object a method returns can be referenced by a variable of type System.Object. Also, ...

Get From Java to C#: A Developer's Guide 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.