Declaring a class member as *virtual* allows inheriting classes to override the base class behavior.
This is one of the pillars of OOP known as polymorphism.
Declaring a method as *sealed* breaks this inheritance chain., preventing inheriting classes from overriding base class methods.
class BaseClass
{
public virtual void Method_01()
{
Console.WriteLine("BaseClass.Method_01");
}
public virtual void Method_02()
{
Console.WriteLine("BaseClass.Method_02");
}
}
class DerivedClass : BaseClass
{
public override void Method_01()
{
Console.WriteLine("DerivedClass.Method_01");
}
public override sealed void Method_02()
{
Console.WriteLine("DerivedClass.Method_02");
}
}
class Consumer : DerivedClass
{
public override void Method_01()
{
Console.WriteLine("Consumer.Method_01");
}
public new void Method_02()
{
Console.WriteLine("Consumer.Method_02");
}
}
static void Main(string[] args)
{
BaseClass bc;
bc = new DerivedClass();
bc.Method_01();
bc.Method_02();
Console.ReadLine();
bc = new Consumer();
bc.Method_01();
bc.Method_02();
Console.ReadLine();
}
ASP.NET, C#, SQL Server Blog
The ZEN of ASP.NET,C#,SQL Server programming
Categories
- Anonymous Methods (1)
- C# 3.0 Feature (1)
- C# 3.0 Features (1)
- Creating HTML Table Dynamically (1)
- DataView Advanced Filtering with Relationships in C# And ASP.NET (1)
- DataView and DataTable Sorting (1)
- Deserialisation between any objects (1)
- Dynamically Adding Multiple Data Tables Relationships (1)
- Filtering Data in a DataTable (1)
- How to Write Stored Procedures (1)
- Implicitly Typed Local Variables (1)
- Internet Explorer (1)
- Lambda Expressions (1)
- Lamda Expression (1)
- LinQ (1)
- LinQ to XML (1)
- Minimize All (1)
- Object Initializing (1)
- Reading the XML file (1)
- Runnig batch script from C# (1)
- Running Process from C# (1)
- Script Manager (1)
- Serialisation (1)
- SHDocVw (1)
- Sorting with a DataView (1)
- Stored Procedures (1)
- Tips and Tricks VS 2010 (1)
- Update Controls Outside Update Panel With Out Postback (1)
- Update Panel (1)
- Using Two Arguments in a Lambda Expression (1)
- Windows 7 (1)
- XML node traversal (1)
About Me
Followers
Powered by Blogger.
Blog Archive
Total Hits
Search
©2008. All rights Reserved
: