Hi archana,
the problem is, you try to override a hidden member. That isn't possible in
C#.
Since base1.xyz is hidden in derived1 and derived2 derives from derived1,
the name xyz in derived2 referes to derived1.xyz. The compiler tries to
override derived1.xyz, wich is not possible because it isn't virtual.
You could make derived1 virtual, but that would have another semantic.
Why you want to hide the method at all. You should consider, giving it
another name.
hth
Christof
"archana" <trialproduct2004@yahoo.comschrieb im Newsbeitrag
news:1168328032.322840.242740@42g2000cwt.googlegro ups.com...
Quote:
Hi all,
>
I have one base class and 2 derived class and one method say xyz.
>
in base class i declare xyz as virtual, but i want to override to
override this method in derived2 class and not in derived1 class. but
in derived1 class i want method with same name that is 'xyz'. but don't
want to override here. means say i have following code
>
class base1
{
>
public virtual void xyz()
{
System.Console.WriteLine("base1 xyz");
}
}
>
class derived1 : base1
{
>
public void xyz()
{
System.Console.WriteLine("derived1 xyz");
}
>
}
>
class derived2 : derived1
{
public override void xyz()
{
System.Console.WriteLine("derived2 xyz");
}
}
>
Above code is giving me error. Can anyone tell me why this is
happening. Can't i override base class method in derived2 .
>
Plese correct me if i am wrong.
>
thanks in advance.
>