Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Designing Interfaces in PHP Abstract Classes Abstract Class

challenge task 4 of 4

Challenge Task 4 of 4

In the Mockingbird.php file, create a "Mockingbird" class that inherits from the Bird Class and also uses the Flyable interface. Make sure you define all abstract methods.

Bird.php
<?php

// abstract bird class
abstract class Bird
{
  public $color,$wingspan,$habitat;

public function eat()
{
}
public function sleep(){

}
  public abstract function communicate($type);
}
Mockingbird.php
<?php

// real Mockingbird class (can fly)
class Mockingbird extends Bird {

    public abstract function communicate($type) 


}
Penguin.php
<?php

// real penguin class (cannot fly)
class Penguin extends Bird {

  public function communicate($type) {
  }

}

3 Answers

Daniel Marin
Daniel Marin
8,021 Points

Hi Dipika, This is the full class Mockingbird. So the parent class of a Mockingbird is Bird then we have a contract that we must abide to Flyable The communicate method comes from Bird, the other methods from Flyable which we have to implement.

<?php

// real Mockingbird class (can fly)
class Mockingbird extends Bird implements Flyable
{

  public function communicate($type) {
  }

  public function takeOff() {
  }

  public function land() {
  }

  public function fly($dest) {
  }

}

thanks again :)

Kevin Korte
Kevin Korte
28,148 Points

I deleted your duplicate questions. I'm not familiar with this lesson at all, but what's the error that you're getting? I can take a look at the code challenge and see if I can help.

Daniel Marin
Daniel Marin
8,021 Points

I believe this challenge will need to show the flyable interface file so we can see the methods in there and not simply check all the time for errors. So this is how it needs to work: Even though you extended Bird you still need to implement Flyable:

<?php 
class Mockingbird extends Bird implements Flyable {

  public function communicate($type) {
  }

}

After you're doing this you'll need to define additional methods, when you press recheck you will see those methods that need to be implemented. Try to implement them yourself :)

Those methods are:

takeOff()   
fly($dest)  
land()  

Hi Daniel Marin, I tried a lot but couldn't complete it can you please help me