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
Why we use get set property in c#?
What is using directive in c#?
What is lazy keyword in c#?
How do I count the length of a string in c#?
What are "class access modifiers" in C#?
What is multicast delegate in c# ?
What is dao in c#?
What is an argument in c#?
What is difference between dictionary and hashtable?
What is appdomain in c#?
What is type class in c#?
Where are value types stored in c#?
What is the difference between constants and read-only?
What does async mean in c#?
Is it possible to execute multiple catch block for a single try statement?