Ajax-loader-large-white
Objects in PHP
Putting It All Together, Part II

Good job, we're almost there. :-)

Now let's add two further methods and let's create some objects.

Instructions
  1. Add a public method to the Dog class called bark(), which returns "Woof!".
  2. Add a public method called greet() to the Dog class. This method ought to return a nice sentence containing the $name property of the Dog, which introduces himself.
  3. Create two instances of the Dog class and store the one with the $name "Barker" in the variable $dog1 and the other one with the $name "Amigo" in the variable $dog2.
  4. As you might have expected, call the bark() method on $dog1 and echo the result.
  5. The last one: Call the greet() method on $dog2 and echo the result.
?
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

Even more syntax remainders ahead:

Adding public methods (in a class):

public function meth1() {
  return "Some text ";
}
public function meth2() {
  return "Some text " . $this->name . " some further text";
}

Creating an instance (outside):

$obj1 = new Classname($prop2);

Calling a method on an instance and printing the result:

echo $obj1->meth2();
index.php
style.css
project
View Preview