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

Kevin Korte
MOD
Kevin Korte
Treehouse Moderator 28,007 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,008 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

Daniel Marin
Daniel Marin
8,008 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 :)