Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Methods Inheritance?
01-05-2011, 12:27 PM #1
- Join Date
- Jan 2011
- Thanked 0 Times in 0 Posts
I am looking for some help with the following question.
I have 2 classes, Bird and AngryBird. AngryBird is a extension of Bird.
Both classes have a method called changeColour() which do different things.
If I use changeColour() in the AngryBird Class it automatically runs the AngryBird's changeColour() method.
What I am looking to do is make it so that, the attributes from the Bird's changeColour() method are also given to an object I use changeColour on...
If I have an object called bird1 as an AngryBird. If I put bird1.changeColour();
I would like the object to run through the Bird changeColour method and the AngryBird ChangeColour method.
Is this possible?
I am not sure if I have been 100% clear, I can post some code if its easier when I get home from work.
01-05-2011, 01:35 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,650 Times in 2,619 Posts
You are not being clear. For attributes are you meaning your class members or are you meaning your method parameters?
For member properties, you need to flag them as protected and not private if you want to directly access them from an extended class. Parameters have to match, otherwise you are not overriding the changeColour method and only overloading it with a new definition.PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');