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
What is difference between a constant and read-only in C#?
How do I create a multilanguage?
What is difference between int and int in c#?
What is a boolean c#?
What is generic types in c#?
How do I format a string in c#?
What is the use of constructor in c# with example?
What's the difference between WindowsDefaultLocation and WindowsDefaultBounds?
What is the purpose of static?
What is option parameter in C#?
Explain the top reason to use c# language?
What can you do as a .net developer?
Why does dllimport not work for me?
Why do we use stringbuilder in c#?
What is serializable in c#?