-
A class that cannot be inherited
Question asked by visitor swatantra
How do i create a class that cannot be inherited neither i should be able to create an object of that class?
-
Junior Member
Re: A class that cannot be inherited
ya u can do this by using 'sealed' key word in definition of a class.But we can create an object of that class
-
Junior Member
Re: A class that cannot be inherited
To create an un-instantiable class add private keyword to the default constructor.
-
Contributing Member
Re: A class that cannot be inherited
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.......
-
Expert Member
Re: A class that cannot be inherited
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules