Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to make a class not inheritable other than sealed?

Answers were Sorted based on User's Feedback



How to make a class not inheritable other than sealed?..

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

How to make a class not inheritable other than sealed?..

Answer / rasik bihari

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 to make a class not inheritable other than sealed?..

Answer / bikas pandey

Declare The Class Modifier As Private

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What is Serialization and how do we implement (in real time scenario)

1 Answers  


What are cookies in c#?

0 Answers  


What are the different types of classes?

0 Answers  


Define a partial class?

0 Answers  


Are private class-level variables inherited?

5 Answers   HCL, Siebel Systems, Visual Soft,


What is Delegate and what is it used for ?

0 Answers   NA,


Can you store multiple data types in System.Array?

20 Answers   Satyam, Siebel Systems,


What is the default value of guid in c#?

0 Answers  


List down the commonly used types of exceptions in .net

0 Answers  


What is a console device?

0 Answers  


What is the difference between finally and finalize block?

0 Answers  


What is the Use Of Interfaces? For example I have a interface as shown below? Interface IMyInterface { public void MyMethod(); } class MyClass : IMyInterface { public void Mymethod() { Some Code } } class Program { static void Main(string[] args) { MyClass obj = new MyClass(); obj.MyMethod(); } } Here What is My Question is? If i remove Interface and run this code, it will executed then what is the Use of the interface? Can any one give me the solution for this Problem? Thanks in Advance!

1 Answers   HCL,


Categories