Results 1 to 5 of 5

Thread: What is an Inheritance in C#?

  1. #1
    Join Date
    Aug 2006
    Posts
    122

    What is an Inheritance in C#?

    Hi friends,
    I am new to the programming language. And I have started with the C# language. I have gone through the Inheritance, but I was unable to understand clearly. There are lot of doubts regarding the inheritance. So can anyone tell me what is an Inheritance in C#? Please help me soon..!!!
    As you simplify your life, the laws of the universe will be simpler; solitude will not be solitude, poverty will not be poverty, nor weakness.Henry David Thoreau

  2. #2
    Join Date
    Nov 2008
    Posts
    996

    Re: What is an Inheritance in C#?

    you should have enough knowledge about the Classes and Structs before moving to the Inheritance in C#. Classes and Structs are ‘blue-prints’ or templates from which we create objects. An object can be of the following types – Class or Struct . Also an Inheritance is one of the most important characteristic of OOP. Classes are also called reference types Structs are known as value types Classes.

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: What is an Inheritance in C#?

    C# supports two types of Inheritance mechanisms
    1. Implementation Inheritance
    2. Interface Inheritance

    Implementation Inheritance - When a class is derived from another class is called as implementation inheritance.
    Interface Inheritance - When a type inherits only the signatures of the functions from another type it is interface inheritance.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: What is an Inheritance in C#?

    I think that providing the syntax of both types of implementation will help you, so I provided that :
    Following is an syntax example for using Implementation Inheritance :
    Code:
    Class derivedClass:baseClass
    {
    }
    derivedClass is derived from baseClass
    The following is an example of Interface Inheritance :
    Code:
    private Class derivedClass:baseClass , InterfaceX , InterfaceY
    {
    }
    derivedClass is now derived from interfaces.

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is an Inheritance in C#?

    You can use the following example for knowing about the Inheritance in C# :
    Code:
     using System;
    
    public class ParentClass
    {
        public ParentClass()
        {
            Console.WriteLine("Parent Constructor.");
        }
    
        public void print()
        {
            Console.WriteLine("This is a Parent Class.");
        }
    }
    
    public class ChildClass : ParentClass
    {
        public ChildClass()
        {
            Console.WriteLine("Child Constructor.");
        }
    
        public static void Main()
        {
            ChildClass child = new ChildClass();
    
            child.print();
        }
    }

Similar Threads

  1. Replies: 3
    Last Post: 08-01-2011, 06:32 AM
  2. What does Inheritance mean in java?
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 11:45 AM
  3. What are the advantages of Inheritance?
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 01-02-2010, 12:28 PM
  4. What are the different types of Inheritance in C++?
    By Techno Guru in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 01:37 PM
  5. Inheritance of Template in C#
    By KADEEM in forum Software Development
    Replies: 4
    Last Post: 07-12-2009, 10:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,502,466.48665 seconds with 17 queries