is it possible to inherit a class but methods declared in
the class should not be inheritable i possible how?
Answers were Sorted based on User's Feedback
Answer / aakanchha
Yes..!!
We can define a method as "private" ,so the method will not
be inherited.
and by 'sealed' we can prevent overriding but can not
prevent inheriting .
| Is This Answer Correct ? | 17 Yes | 1 No |
Answer / arunkumar
s it is possible by doing Sealed keyword to the method in
first class
| Is This Answer Correct ? | 21 Yes | 8 No |
Answer / 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 |
Answer / vishal
That's Correct.
Using private keyword in the method signature is a way of
preventing inheritance of that method in child class.
Please note that using "sealed" keyword in method signature
only prevents overriding of the method in child class, but
the method is still inheritable in the child class.
| Is This Answer Correct ? | 8 Yes | 0 No |
Answer / bikas pandey
Let The Class To Public And The Method To Be Sealed
| Is This Answer Correct ? | 1 Yes | 4 No |
Answer / rajni
yes it is possible for method not to inherit make it final.
| Is This Answer Correct ? | 0 Yes | 5 No |
what is full assembly reference
What is a private constructor? where will you use it?
What is the state of Garbage Collection after dispose() call info C# code?
Types of polymerphism and explain about dynamic polymerphism?
how to use msflexgrid in asp.net
Can you allow class to be inherited, but prevent the method from being over-ridden?
What are the properties of a string class?
Is c# an open source?
What is IL / CIL / MSIL?
Can you pass value types by reference to a method?
What is the difference between hashtable and dictionary in c#?
What are circular references? How garbage collection deals with circular references.
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)