How would you stop a class from class from being derived or
inherited.
Answers were Sorted based on User's Feedback
Answer / satya
By Declaring the Class as 'Sealed' in C# or
as "NotInheritable" in VB.NET
Is This Answer Correct ? | 8 Yes | 3 No |
Answer / deepak joshi
Guys what happened to you all???? Will 'Final' not do????
Is This Answer Correct ? | 8 Yes | 4 No |
Answer / stavanm
By Creating class as a final
final class A{
// code
}
Is This Answer Correct ? | 5 Yes | 1 No |
#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 |
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 |
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 |
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 |
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 |
What is a class in oop?
Which is better struts or spring?
diff between Abstract class Interfaces?
write a function that takes an integer array as an input and finds the largest number in the array. You can not sort array or use any API or searching needs?
2 Answers IBMS, Zycus Infotech,
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.
can inline function declare in private part of class?
What is encapsulation process?
Why do we use inheritance?
Write a program to sort the number with different sorts in one program ??
Can we have inheritance without polymorphism?
write a program to find the largest of two numbers without using for,while,switch,if else, conditional operator and do while using c++ pgmng language
create a class complex having real and imaginary part of a complex no. as a data member. overload the binary operators(+,- and *) to perform the operations on complex no. objects. overload binary operator using friend function.
2 Answers CTS, Delhi University,