Can you prevent your class from being inherited and becoming
a base class for some other classes?

Answers were Sorted based on User's Feedback



Can you prevent your class from being inherited and becoming a base class for some other classes?..

Answer / guest

Yes, that?s what keyword sealed in the class definition is
for. The developer trying to derive from your class will get
a message: cannot inherit from Sealed class
WhateverBaseClassName. It?s the same concept as final class
in Java

Is This Answer Correct ?    2 Yes 1 No

Can you prevent your class from being inherited and becoming a base class for some other classes?..

Answer / srivathsan

@ guest...
the answer is not incomplete.

it is implicit. Rakesh wants to tell that the sealed
methods cannot be inherited from a class that is not
sealed, even when you inherit other members from a class
that is not decorated with the keyword sealed.

Is This Answer Correct ?    1 Yes 0 No

Can you prevent your class from being inherited and becoming a base class for some other classes?..

Answer / rakesh

We can also make the methods sealed.In that case ,the class
can inherit but the sealed methods in that class cannot

Is This Answer Correct ?    0 Yes 0 No

Can you prevent your class from being inherited and becoming a base class for some other classes?..

Answer / guest

Rakesh are u keeping us in Suspense?

u must complete the answer.

but the sealed methods in that class cannot........??????

Is This Answer Correct ?    0 Yes 0 No

Can you prevent your class from being inherited and becoming a base class for some other classes?..

Answer / pank

Make your class constructor as Private then it will restrict from being inherit as well as instantiate.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

Why do we need abstract class?

0 Answers  


What is difference between ienumerable and list in c#?

0 Answers  


what is output parameter and parameter array?

1 Answers   TCS,


Can we inherit class that contains only one private constructor?

0 Answers  


What is the difference between protected and internal in c#?

0 Answers  






What are the properties of c#?

0 Answers  


What is the use of "default" and "Using" keyword?

3 Answers   TCS,


Could you explain the difference between func vs action vs predicate?

0 Answers  


Explain ACID rule of thumb for transactions.

1 Answers  


Why do we use partial class in c#?

0 Answers  


What is anonymous class in c#?

0 Answers  


In which order the constructor is called for an inherited class?

0 Answers  


Categories