Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Model a Simple Inheritance Hierarchy | OOP Principles and Advanced Features
Object-Oriented PHP

bookChallenge: Model a Simple Inheritance Hierarchy

Recap: Inheritance, Visibility, and Overriding

You have learned that inheritance allows you to create a new class based on an existing one, using the extends keyword. This lets you reuse code and build logical relationships between classes. Visibility keywords—public, private, and protected—control which properties and methods are accessible from outside or inside the class and its subclasses. Method overriding lets a subclass provide its own implementation of a method defined in its parent class.

You are now ready to apply these concepts by modeling a simple class hierarchy representing animals and their behaviors.

Tarefa

Swipe to start coding

Create a class hierarchy to model animals and their sounds.

  • Define a base class Animal with a public method speak() that outputs a generic message.
  • Define a subclass Dog that extends Animal and overrides speak() to output a dog-specific sound.
  • Define a subclass Cat that extends Animal and overrides speak() to output a cat-specific sound.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 6
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

close

bookChallenge: Model a Simple Inheritance Hierarchy

Deslize para mostrar o menu

Recap: Inheritance, Visibility, and Overriding

You have learned that inheritance allows you to create a new class based on an existing one, using the extends keyword. This lets you reuse code and build logical relationships between classes. Visibility keywords—public, private, and protected—control which properties and methods are accessible from outside or inside the class and its subclasses. Method overriding lets a subclass provide its own implementation of a method defined in its parent class.

You are now ready to apply these concepts by modeling a simple class hierarchy representing animals and their behaviors.

Tarefa

Swipe to start coding

Create a class hierarchy to model animals and their sounds.

  • Define a base class Animal with a public method speak() that outputs a generic message.
  • Define a subclass Dog that extends Animal and overrides speak() to output a dog-specific sound.
  • Define a subclass Cat that extends Animal and overrides speak() to output a cat-specific sound.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 6
single

single

some-alt