Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Creating a Vehicle Hierarchy | Introdução à OOP em Python
Practice
Projects
Quizzes & Challenges
Questionários
Challenges
/
Programação Orientada a Objetos em Python

bookChallenge: Creating a Vehicle Hierarchy

Tarefa

Swipe to start coding

Define a class hierarchy for different types of vehicles:

  • Create a base class named Vehicle with an __init__ method that takes brand and speed as arguments.
  • Add a method called get_info to Vehicle that returns the brand and speed.
  • Create a subclass Car that inherits from Vehicle and adds a doors attribute.
  • Create a subclass Bike that inherits from Vehicle and adds a type attribute (such as 'mountain' or 'road').
  • Override the get_info method in both Car and Bike to include their extra data (doors for cars, type for bikes).

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 10

Pergunte à IA

expand

Pergunte à IA

ChatGPT

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

bookChallenge: Creating a Vehicle Hierarchy

Deslize para mostrar o menu

Tarefa

Swipe to start coding

Define a class hierarchy for different types of vehicles:

  • Create a base class named Vehicle with an __init__ method that takes brand and speed as arguments.
  • Add a method called get_info to Vehicle that returns the brand and speed.
  • Create a subclass Car that inherits from Vehicle and adds a doors attribute.
  • Create a subclass Bike that inherits from Vehicle and adds a type attribute (such as 'mountain' or 'road').
  • Override the get_info method in both Car and Bike to include their extra data (doors for cars, type for bikes).

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 10
some-alt