How would you stop a class from class from being derived or
inherited.

Answers were Sorted based on User's Feedback



How would you stop a class from class from being derived or inherited...

Answer / satya

By Declaring the Class as 'Sealed' in C# or
as "NotInheritable" in VB.NET

Is This Answer Correct ?    8 Yes 3 No

How would you stop a class from class from being derived or inherited...

Answer / deepak joshi

Guys what happened to you all???? Will 'Final' not do????

Is This Answer Correct ?    8 Yes 4 No

How would you stop a class from class from being derived or inherited...

Answer / stavanm

By Creating class as a final

final class A{
// code
}

Is This Answer Correct ?    5 Yes 1 No

How would you stop a class from class from being derived or inherited...

Answer / srini

#define DO_NOT_DERIVE(T) \
class NoDerive_##T { \
friend class T;
\
NoDerive_##T() {}
\
NoDerive_##T(const NoDerive_##T&) {} \
};
#define stopderiving(T) private virtual NoDerive_##T

when we derive from any class, the constructor needs to be
called, since here constructor of NoDerive calss is
private, it cannot be derived. And friendship cannot be
inherited.
usage
class finalclass : stopderiving (finalclass)
{
....
};

the other possible solution for this is making the default
constructor private.

Is This Answer Correct ?    4 Yes 1 No

How would you stop a class from class from being derived or inherited...

Answer / bala

Final will do in Java. But not in C++.

I hope, bye creating all the constructor,copy constructor
in private will stop inherite the class.
Plz refer 'Singleton Pattern'

Is This Answer Correct ?    1 Yes 1 No

How would you stop a class from class from being derived or inherited...

Answer / selvam

but onething.If you make constructor as private you will
not be able to create an object of that class.

Is This Answer Correct ?    0 Yes 0 No

How would you stop a class from class from being derived or inherited...

Answer / montylee

Here's the correct answer:
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.11

Is This Answer Correct ?    0 Yes 0 No

How would you stop a class from class from being derived or inherited...

Answer / anant tiwari

There are three way to stop a class been derived (example in C#)
1) declare a class as static (Ex : static class Sample {....}
2) declare the class constructor as private (Ex class Sample{ private Sample(){}....}
3) declare a class as sealed class Ex : sealed class Sample {...}

Is This Answer Correct ?    0 Yes 0 No

How would you stop a class from class from being derived or inherited...

Answer / dom wadegu

by declearing a sub-class protected.

Is This Answer Correct ?    0 Yes 0 No

How would you stop a class from class from being derived or inherited...

Answer / ravinandan

Make constructor of the class as private.

Is This Answer Correct ?    7 Yes 8 No

Post New Answer

More OOPS Interview Questions

What is class and example?

0 Answers  


Is html an oop?

0 Answers  


what is difference between class template and template class?

0 Answers  


What is polymorphism give a real life example?

0 Answers  


Why is oop useful?

0 Answers  






What does the keyword "static" mean?

4 Answers   TCS,


WHAT IS THE ACTUAL DEFINATION OF OBJECT AND THE CLASS IN ONE SINGLE LINE WHICH THE INTERVIEWER WANT TO LISTEN.

11 Answers  


officer say me - i am offered to a smoking , then what can you say

0 Answers  


What makes a language oop?

0 Answers  


i ahve v low % in 12th n BSC which is aroun 50 coz science was imposed on me......nw m doin MCA n my aggregate in above 74%,what shud i say if asked about low previous percentage??????

4 Answers  


What is the main purpose of inheritance law?

0 Answers  


What are benefits of oop?

0 Answers  


Categories