Contenido del Curso
Java OOP
Java OOP
Challenge: Interface
Task
For you, two interfaces have been created: Human
and Animal
, as well as one class – Werewolf
.
Your task is to inherit both interfaces in the Werewolf
class and then implement their methods. In the Werewolf
class, the comments above indicate how you should override these methods. A werewolf is both a human and an animal, so it has a method called transform()
. You should also use the boolean value isHumanForm
in the methods as instructed.
If the task seems difficult, feel free to use the Hint and Solution buttons to analyze the solution!
transform()
method and do not edit the fields.
Werewolf
class, you should implement two interfaces –
Human
and Animal
. Do this using the syntax
implements Human
, Animal
.
@Override
annotation from both
interfaces.
speak()
method should check the boolean value
isHumanForm
and if the answer is true
, return "I am a human.". If the value is false
, return "I cannot speak in wolf form.".
sound()
method should check the boolean value
isHumanForm
and if the answer is true
, return "No sound in human form.". If the value is false
, return "Howl!".
¿Todo estuvo claro?
Contenido del Curso
Java OOP
Java OOP
Challenge: Interface
Task
For you, two interfaces have been created: Human
and Animal
, as well as one class – Werewolf
.
Your task is to inherit both interfaces in the Werewolf
class and then implement their methods. In the Werewolf
class, the comments above indicate how you should override these methods. A werewolf is both a human and an animal, so it has a method called transform()
. You should also use the boolean value isHumanForm
in the methods as instructed.
If the task seems difficult, feel free to use the Hint and Solution buttons to analyze the solution!
transform()
method and do not edit the fields.
Werewolf
class, you should implement two interfaces –
Human
and Animal
. Do this using the syntax
implements Human
, Animal
.
@Override
annotation from both
interfaces.
speak()
method should check the boolean value
isHumanForm
and if the answer is true
, return "I am a human.". If the value is false
, return "I cannot speak in wolf form.".
sound()
method should check the boolean value
isHumanForm
and if the answer is true
, return "No sound in human form.". If the value is false
, return "Howl!".
¿Todo estuvo claro?