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
Are c# objects passed by reference?
What is yield return in c#?
Why do we need structs in c#?
what is difference between destruct or and garbage collection ?
What is expandoobject in c#?
Write the syntax for catching an exception in c#?
What is difference between il and dll ?
Is c# queue thread safe?
What is func delegate in c#?
What is task parallel library?
How is method overriding different from overloading?
Is array passed by reference in c#?
What is difference between array and arraylist in c#?
Which is more efficient for loop or while loop?
Differentiate between sqlclient oledb and providers?