No. All classes are derivable. You can, however, make it unsafe to derive from a class by not making the destructor virtual. Then derived classes will not be able to safely and polymorphically free resources.
I have listen many discussion about "class which can not be inherited". I got answer also if we
declare constructor as private than no one can inherited class.
But did anyone find any practical example or scenario which they use "final class". I am working
on large code base but I did not find any example
You can make a class non inheritable by making the constructor private. This way child classes will not be able to create objects. But to create the parent class object you can give any static method as an interface to create an object and return an instance. singleton classes usually does this.
I don't consider STL to be in error by not declaring destructors as virtual. Rather, it follows the C++ mantra
of not making the user pay for features they don't use. Introducing a virtual destructor introduces a
vtable, which causes all users to pay for an extra pointer even if they aren't using the container polymorphically.
Sutter and Alexandrescu, in C++ Coding Standards, argue that you should prefer composition to inheritance.
In practice, this means writing a bunch of forwarding functions to "simulate" inheritance, which will result in
no overhead so long as the forwarders are inlined.
singleton is NOT a way to prevent inheritance. it is a way to prevent more than one instantiation.
private constructor can not prohibit inheritance either. it just disallows any instantiation of higher hierarchy class.
No matter what, you can always inherit,
but you can not always get instantiation from inheritance.
"need a final class in the code base" is equivalent to saying "don't want someone to
derive from it". The only real reason you wouldn't want someone to derive from
a class is because the class does not have a virtual destructor and therefore will not
work correctly in a polymorphic context.
I didn't say that singletons are to prevent inheritance. I just gave an example of providing an interface to create an instance instead of a constructor so that objects can be instantiated.
To everid: inheritance is always there, but when we prevent a child class instantiation literally means the child class is useless and the base class can't be inherited.