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 form feed and carriage return?
Can we inherit private class in c#?
Can a constructor be private in c#?
Which controls do not have events?
How many types of namespaces available in version4?
Why is it called c sharp?
How to achieve polymorphism in c#?
How do you mark a method obsolete?
Explain the difference between passing parameters by value and passing parameters by reference with an example?
Does console.writeline() stop printing when it reaches a null character within a string?
What's new in c#?
What’s a strong name?
Is 0 an unsigned integer?
What is static void main in c#?
Distinguish between array and arraylist in c#?