If Base class permits ovverridding then we should provide 'virtual' keyword in base class.
If data hiding is intended then its better to provide 'new' keyword in derived class
here is an example
class Abs_class
{
public string display()
{
return ("Hello");
}
public virtual void sample()
{
}
}
class myclass : Abs_class
{
public int show(int a, int b)
{
return (a + b);
}
public new string display() //since base doesnot allow ovverride ,u can provide new definition
{
return ("derived class's display");
}
public override void sample()
{
//implement sample fn.
}
public string myownfn()
{
return ("Hi im derived class fn");
}
}
class Demo
{
public static void Main(string[] args)
{
myclass m1 = new myclass();
Console.WriteLine(m1.display());
Console.Read();
}
}
0 comments:
Post a Comment