[b]Question asked by visitor swatantra[/b]
How do i create a class that cannot be inherited neither i should be able to create an object of that class?
Printable View
[b]Question asked by visitor swatantra[/b]
How do i create a class that cannot be inherited neither i should be able to create an object of that class?
ya u can do this by using 'sealed' key word in definition of a class.But we can create an object of that class
To create an un-instantiable class add private keyword to the default constructor.
Hi,
u can use sealed keyword before class declaration or u can create private constructor(default constructor) in a class that class should not be inheritable because the private constructor is not accessiable in derived class every derived class will call the base class default constructor.
if u have any queries let me know.......
A class that cannot be inherited and should not allow to create object is of no use. why u want to do that?
Sealed classes cannot be inherited.
Abstract classes cannot be instantiated.
but i think C++ won't allow u to declare a class as both sealed and abstract as it has no use practically. (i remember reading this somewhere)