Place Ads here

Monday, July 25, 2011

Inheritance



 

 

 

 

              

 Inheritance











2E: A Learner's Guide to Real-World Programming with Visual C# and .NET (Head First Guides]Asp.Net sample projects
How to use inheritance in c# asp.netSource Code to use Inheritance in c# Asp.Net
 Inheritance
Inheritance is a feature of Object Oriented Programming language.
Inheritance is a way of communication  between classes.
In Inheritance one is a parent class and other is a child class.
In Inheritance parent class is called as base class and child class is called as sub class.
Inheritance Creates hierarchy of Objects.
In C#,Inheritance is a process of  creating type such as a class or interface from an existing type such as a class or interface.

Source Code to use Inheritance in c# asp.netusing System;
public class parentclass
{
public parentclass()                          ////I am coding a constructor
{
Console.Writeline("Hi, My name is Amul.I am a parentclass constructor.");
Console.Writeline("I have same name as a class name.");
Console.Writeline("");
}
public void  parentclassmethod()              //// I am coding a Method
  {
Console.Writeline("There is no need to create an Object for me as I am a constructor.(parentclass constructor.)");
Console.Writeline("I get Invoked Automatically.So Whatever is written in constructor is invoked first.");
Console.Writeline("Because of Me as a Constructor,Loading time required  is less.");
Console.Writeline("");
 }
}

public class childclass : parentclass    //////ParentClass is a base class of ChildClass.
                                                       //////ChildClass inherites the functionalities of ParentClass
{
public childclass()                          //////I am coding a constructor
{
                 Console.Writeline("Hi , I am Clone of Amul. I am a childclass constructor.");
                     Console.Writeline("I also have a name as that of class name.");
                        Console.Writeline("");
}

public void childclassmethod()         //// I am coding a Method
{
Console.Writeline("There is no need to create an Object for me  also as I am a constructor.(childclass constructor.)");
Console.Writeline("I get Invoked Automatically.So Whatever is written in constructor is invoked first.");
Console.Writeline("Because of Me as a Constructor, Loading time required  is less.");
Console.Writeline("");
}

public static void Main()
{
       childclass  object1 = new childclass();
       childclass.parentclassmethod();
       childclass.childclassmethod();
}
}
OUT PUT        //////For Inheritance
Hi, My name is Amul.I am a parentclass constructor.        
I have same name as a class name.
Hi , I am Clone of Amul. I am a childclass constructor.
I also have a name as that of class name.

There is no need to create an Object for me as I am a constructor.(parentclass constructor.)
I get Invoked Automatically.So Whatever is written in constructor is invoked first.
Because of Me as a Constructor, Loading time required  is less.

There is no need to create an Object for me also as I am a constructor.(childclass constructor.)
I get Invoked Automatically.So Whatever is written in constructor is invoked first.
Because of Me as a Constructor, Loading time required  is less.
.
 

No comments:

Post a Comment