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
Explain the use of SN.exe
What are get and set in c#?
What is option parameter in C#?
Is c# good for games?
Can you create an instance of a static class?
Why is it called c sharp?
What is assembly manifest?
Explain how many types of exception handlers are there in .net?
Explain the difference between proc. Sent by val and by sub?
What is namespace explain with example?
What is string method in c#?
Is null == null c#?
What is difference between managed and unmanaged code?
In c#, what will happen if you do not explicitly provide a constructor for a class?
What is an arraylist in c#?