C# FAQ: What are the differences between CSharp and Java inheritance syntax

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

What are the differences between C# and Java inheritance syntax?

What are the differences between C# and C++ inheritance syntax?

Whereas the Java language uses the extends and implements keywords, C# uses the C++ inheritance syntax for class inheritance (:) and for interface implementation (,) respectively.

using System;                                  // C# example
class Sub : Super, IComparable
{
   int CompareTo(){}
 
   public static void Main(String[] args)
   {
   }
}
class Sub extends Super implements Comparable  // Java example
{
   int compareTo(){}
 
   public static void main(String[] args)
   {
   }
}

According to .NET naming conventions, interface names should begin with an uppercase "I", e.g. IComparable. This is a useful convention since—unlike the Java syntax—the C# syntax does not make it obvious who is subclassing whom.

See also


Personal tools