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
Does c# support c type macros?
What does it mean to override a method?
How to create events for a control? What is custom events? How to create it?
What is the meaning of extention?
What is the ouput of the following program?
How do you comment in c#?
Explain about finalize method?
Why we use oops in c#?
What is difference between C# and VB.NET?
Why we use dll in c#?
What are functions in c#?
What is Garbage Collection in .Net?
What is the use of partial methods?
What are partial types in c#?
What is class and object c#?