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 |
What does void mean unity?
What is a sealed class?
Are private class-level variables inherited?
What is difference between a type and class?
What is sqladapter c#?
What is jagged array?
How many constructors can a class have in c#?
What is list array in c#?
What is parallel programming in c#?
How to open a new form on button click in Windows forms?
What is the use of jit ? Jit (just - in - time) is a compiler which converts msil code to
Why do we need to override in c#?