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


Please Help Members By Posting Answers For Below Questions

What is the base class of all classes in c#?

502


Are string objects mutable or immutable?

526


What is a class level variable in c#?

493


What are namespaces, and how they are used?

561


What is datarelation c#?

461






Can you declare a class or a struct as constant?

540


What is the compiler of c#?

487


Does hashset allow duplicates c#?

511


i want o/p 011242110 in c# code.

1628


Why do we need a singleton class?

500


What is console used for?

515


What is xor operator in c#?

512


What is reflection in c#?

489


What is difference between asp net and c# net?

479


Can we override main method in c#?

474