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 are All kind of access specifiers for a class and for methods
What is data dictionary in c#?
What does using do in c#?
What are different types of Delegates in C#?
What is the difference between CONST and READONLY?
What is the advantage of static class in c#?
Why do we use class in c#?
What is difference between a constant and read-only in C#?
Which is better javascript or c#?
Explain dataadapter.update method in .net?
What is the difference between out and ref in c#?
What is an extension method in c#?
Why use a singleton instead of static methods?
What is a static class in c#?
User's session is explicitly killed by which method ?