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 the base class of all classes in c#?
Are string objects mutable or immutable?
What is a class level variable in c#?
What are namespaces, and how they are used?
What is datarelation c#?
Can you declare a class or a struct as constant?
What is the compiler of c#?
Does hashset allow duplicates c#?
i want o/p 011242110 in c# code.
Why do we need a singleton class?
What is console used for?
What is xor operator in c#?
What is reflection in c#?
What is difference between asp net and c# net?
Can we override main method in c#?