Originally posted by Puneet Agarwal:
Lets say we have 2 classes A and B . B is derived from A .
How can I achieve a situation where I should be able to create an object of B , but not of A . Is it possible....
P.S. - A cannot be made abstract , it is a proper class.
Mona(Varijasmom)
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
I think I am a bit confused here . How can you instantiate a child class object if you declre the base class constrctor as private .
My question is to allow the creation of a derived class but not the Base class.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
ur code gave errors when i tried to run it,
Error #: 306 : constructor B() has private access in class untitled1.B at line 16, column 3
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|