How to make a class not inheritable other than sealed?
Answers were Sorted based on User's Feedback
Answer / lalit pradhan
Hey guys this is practically tested answer:
namespace Test
{
class Program
{
static void Main(string[] args)
{
A a = new A();
a.Method();
//B b = new B();
//b.Method("From B");
C c = new C();
Console.ReadKey();
}
}
class A
{
public void Method()
{
Console.WriteLine("From A");
}
}
static class B : A
{
public void Method(string s)
{
Console.WriteLine(s);
}
//void calculate();
}
class C : B //Here you will notice that B's color is
not highlighted to green when its not inheritable
{
public void Final()
{
Console.WriteLine("I am Final Method");
}
}
}
Enjoy!!!
Lalit Pradhan a.k.a DOTNET Gadhaa
| Is This Answer Correct ? | 1 Yes | 0 No |
I don't agree with this (Answer # 1) as Making the class as
private will prevent it from even being initialized or
instantiated. I don't have the answer myself :-)
| Is This Answer Correct ? | 0 Yes | 0 No |
How do you declare an interface in c#?
Hi to everybody. Lastweek i had taken an interview on c#. They ask what is boxing & unboxing, Masking.Please tell the answer and it is useful for me.
Explain what are three test cases you should go through in unit testing?
What is generic types in c#?
What is iqueryable and ienumerable in c#?
What are the different types of comments in c#?
What is concrete class in c#?
if i want to transmit binary data,,,will it be support by Webservices or any exceptions ? define
What is xml serialization in c#?
What is private class in c#?
Can an array be null c#?
What language is c# similar to?
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)