Objects in PHP
Challenge Time

Awesome! Now let's try the same without the training wheels. :-P

Let's create a Cat class, which has two public properties: an $isAlive property storing the value true and a $numLegs property containing the value 4.

There should be a public $name property, which should get a value when a new object is created, so assign the value to $name via the __construct() method.

Then I also want these Cats to be able to meow, so add a meow() method, which returns "Meow meow".

Finally, create an instance of the Cat class, which has the $name "CodeCat" and store it in the variable $cat1. Then call the meow() method on this cat.

Sounds doable? Then let's start the challenge. :-)

  1. Create a class called Cat.
  2. Add two public properties to this class: $isAlive ought to store the value true and $numLegsshould contain the value 4.
  3. Add a public $name property, which gets its value via the __construct()or.
  4. Add a public method called meow(), which returns "Meow meow".
  5. Create an instance of the Cat class, which has the $name "CodeCat".
  6. Call the meow() method on this Cat and echo the result.
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

Sorry, this is your challenge, so I mustn't help you. :-(

Feel free to visit the last exercises, if you need a syntax refresher. :-)

View Preview