is it possible to inherit a class but methods declared in
the class should not be inheritable i possible how?

Answer Posted / ashish modi

class X
{
protected virtual void F() { Console.WriteLine("X.F"); }
protected virtual void F2() { Console.WriteLine
("X.F2"); }
}
class Y : X
{
sealed protected override void F() { Console.WriteLine
("Y.F"); }
protected override void F2() { Console.WriteLine
("X.F3"); }
}
class Z : Y
{
// Attempting to override F causes compiler error
CS0239.
// protected override void F() { Console.WriteLine
("C.F"); }

// Overriding F2 is allowed.
protected override void F2() { Console.WriteLine
("Z.F2"); }
}

Is This Answer Correct ?    12 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why we use get set property in c#?

573


What is using directive in c#?

615


What is lazy keyword in c#?

605


How do I count the length of a string in c#?

580


What are "class access modifiers" in C#?

616






What is multicast delegate in c# ?

628


What is dao in c#?

568


What is an argument in c#?

583


What is difference between dictionary and hashtable?

624


What is appdomain in c#?

574


What is type class in c#?

572


Where are value types stored in c#?

597


What is the difference between constants and read-only?

558


What does async mean in c#?

595


Is it possible to execute multiple catch block for a single try statement?

679