Results 1 to 5 of 5

Thread: A class that cannot be inherited

  1. #1
    Geek_Guest
    Guest

    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?


  2. #2
    Junior Member
    Join Date
    Apr 2007
    Answers
    1

    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


  3. #3
    Junior Member
    Join Date
    Mar 2007
    Answers
    1

    Re: A class that cannot be inherited

    To create an un-instantiable class add private keyword to the default constructor.


  4. #4
    Contributing Member
    Join Date
    May 2007
    Answers
    60

    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.......


  5. #5
    Expert Member
    Join Date
    Dec 2006
    Answers
    204

    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
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact