multiple inheritance in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • btreddy
    New Member
    • Oct 2008
    • 83

    multiple inheritance in C#

    Hii all ,

    I know that there is no support for multiple inheritance in .NET.

    but if i declare a class like

    Code:
    public class myclass
    {
    
    }
    by default it gets inherited from system.Object.

    and if i inherit the class from class baseclass like below

    Code:
    public class myclass:baseclass
    {
    
    }
    it is equals to
    Code:
    public class myclass:System.Object,baseclass
    {
    
    }
    it means it supports multiple inheritance.Am i correct?

    Thanks & Regards,
    Tirumala Reddy.B
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    It depends upon how you think about it. Yes in your example myClass is derived from 2 classes, but you can't have..

    Code:
    public class myClass: baseClass, baseClass2
    {
    }
    This is why people say C# doesn't support multiple inheritance. On the other hand C# does allow you to inherit from multiple classes assuming that 1 is only a real class and the others are interfaces.

    Code:
    public class myClass : baseClass, IanInterface
    {
    }
    It is just easier to say that C# doesn't support multiple inheritance than to say C# supports multiple inheritance except that...

    Comment

    • btreddy
      New Member
      • Oct 2008
      • 83

      #3
      Thanks for the reply

      But sorry i'm not clear yet.

      what is the difference between the following classes;
      Code:
      public class mycalss{}
      Code:
      public class myclass:System.Object{}
      in both the declarations i'm able to access all the 4 methods that are there in system.object.

      someone can help me in explaining what actually happening inside.

      Thanks in advance

      Rgds,
      Tiru.

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        All objects in C# inherit from object by default, it's just a thing. I think Java does this too. So I believe those are the same.

        Comment

        • btreddy
          New Member
          • Oct 2008
          • 83

          #5
          Thanks Gary for your reply.

          Comment

          Working...