how to use inheritance in asp.net with example
how to use inheritance in asp.net with example
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jun 14, 2012, 11:34 PM
Creating a new class from existing class is called as inheritance.When you derive a class from a base class, the derived class will inherit all members of the base class except constructors, though whether the derived class would be able to access those members would depend upon the accessibility of those members in the base class.
Main advantage of inheritance is reusability of the code.
public class Animal
{
public Animal()
{
Console.WriteLine("Animal constructor");
}
public void Greet()
{
Console.WriteLine("Animal says Hello");
}
public void Talk()
{
Console.WriteLine("Animal talk");
}
public virtual void Sing()
{
Console.WriteLine("Animal song");
}
}
public class Cow : Animal
{
public Cow()
{
Console.WriteLine("Cow constructor");
}
public new void Talk()
{
Console.WriteLine("Dog talk");
}
public override void Sing()
{
Console.WriteLine("Cow song");
}
}
Animal cow = new Cow();
cow.Talk();
cow.Sing();
cow.Greet();
//Output
Animal constructor
cow constructor
Animal talk
cow song
Animal says Hello
please refer
http://www.programcall.com/19/csnet/inheritance-with-an-example-in-csnet.aspx
hope this will help you.
Amit PatelPosted Jun 14, 2012, 11:17 PM
Satyapriya NayakPosted Jun 14, 2012, 9:38 PM
Please refer the below links
http://www.functionx.com/aspnet/classes/inheritance.htm
http://www.programcall.com/19/csnet/inheritance-with-an-example-in-csnet.aspx
http://aspnet.4guysfromrolla.com/articles/041305-1.aspx
http://www.exforsys.com/tutorials/csharp/inheritance-in-csharp.html
http://www.codeproject.com/Articles/1445/Introduction-to-inheritance-polymorphism-in-C
http://www.techrepublic.com/article/establish-common-aspnet-page-features-through-inheritance/5772080
Thanks