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
Why static variables are used?
Explain the difference between object type and dynamic type variables in c#?
Can a constructor be static in c#?
How does the clr work?
Can we inherit two classes in c#?
What is the difference between gettype and typeof in c#?
Does constructor return any value in c#?
How do you clear a list in c#?
Explain the mechanism of VB.NET/C# achieve polymorphism?
Describe ways of cleaning up objects in c#.
Explain the process of polymorphism with an example?
What is assembly c#?
How to implement singleton design pattern in c#?
What does || mean in programming?
What is the difference between c and c# programming?