Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: Add code to a constructor
12-19-2010, 12:20 PM #1
- Join Date
- Nov 2010
- Thanked 0 Times in 0 Posts
Add code to a constructor
As part of an assignment I have being asked to add code to a constructor .
the constructor initializes a dog object to black and its position to 1 in the superclass.
A subclass requires to initialize the dog to white and position to say 2 .
I would be grateful for any pointers to how best achieve this .
12-19-2010, 04:48 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,660 Times in 2,629 Posts
How this is done depends entirely on the properties of the superclass. If the colour and position are both protected or private, than you can write directly to the properties of the superclass. If the superclass accepts a colour and position as a part of its constructor, you can chain the subclass to the superclass with
Chances are if you are required to alter the code, than the superclass does not accept parameters (otherwise an overwrite is completely useless since the subclass can just use the superclass constructors), which will lead me to believe that the properties are likely protected. If they are not, you need mutator's in order to set the new colour and position. In either the these two events, you will be overridding the default superclass constructor.
header('HTTP/1.1 420 Enhance Your Calm');
12-24-2010, 12:14 PM #3
1. I do not believe we are allowed to help you with your assignments.
2. It would be far more helpful to know
a) the source code
b) what you have tried to do so far
If it's a problem with phrasing, ask your professor/teacher