What, exactly, do you have so far, and where are stuck making progress? (Also, you may want to insert a "please" into the last sentence; it sounds so much nicer :-)
sharma ishu wrote:Write a super class that requires each of its sub-class to create a no-arg constructor. Also write its one sub-class.
Help me with this problem.
Hi Sharma,
A superclass can't require it's subclasses to create a no-arg constructor (i.e. a no-arg constructor in the subclass).
Furthermore, it's good OO that a superclass should have no 'knowledge' of it's subclasses.
Ulf Dittmer wrote:What, exactly, do you have so far, and where are stuck making progress? (Also, you may want to insert a "please" into the last sentence; it sounds so much nicer :-)
Can you please give a super-class and it's sub-class code that satisfy the above criteria as soon as possible.
sharma ishu wrote:Write a super class that requires each of its sub-class to create a no-arg constructor. Also write its one sub-class.
Help me with this problem.
Hi Sharma,
A superclass can't require it's subclasses to create a no-arg constructor (i.e. a no-arg constructor in the subclass).
Furthermore, it's good OO that a superclass should have no 'knowledge' of it's subclasses.
Regards,
Al
This question is from "practice exams book by kethy and bates" edition 2011 chapter-4 page-150. So, I think it should have a solution.
sharma ishu wrote:Write a super class that requires each of its sub-class to create a no-arg constructor. Also write its one sub-class.
Help me with this problem.
Hi Sharma,
A superclass can't require it's subclasses to create a no-arg constructor (i.e. a no-arg constructor in the subclass).
Furthermore, it's good OO that a superclass should have no 'knowledge' of it's subclasses.
Regards,
Al
This question is from "practice exams book by kethy and bates" edition 2011 chapter-4 page-150. So, I think it should have a solution.
With respect to the K&B, the question could be written less ambiguously.
"Write a superclass that requires any of its subclasses to create a no-arg constructor [in the superclass]. Write a subclass for this superclass.
With the question in this context, the answer given above by Himai Minh is what you want.
Aside:
One could equally interpret the question as:
"Write a superclass that requires any of its subclasses to create a no-arg constructor [in the subclass(es)]. Write a subclass for this superclass.
In which case my previous answer would suffice.
Alan Cowap wrote:With respect to the K&B, the question could be written less ambiguously.
"Write a superclass that requires any of its subclasses to create a no-arg constructor [in the superclass].
I'm not convinced that's less misleading - how can a subclass create a constructor in the superclass? But you're write it should be phrased differently. The thread Seetharaman linked to discussed likely interpretations (and also had a solution to the problem as stated - though it relied on reflection and definitely wasn't the intended solution of the exercise), and I suspect what you intended the above to mean is right.