Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Creating a Vehicle Hierarchy | Introduktion till Python OOP
Practice
Projects
Quizzes & Challenges
Frågesporter
Challenges
/
Objektorienterad Programmering i Python

bookChallenge: Creating a Vehicle Hierarchy

Uppgift

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).

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 10

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

bookChallenge: Creating a Vehicle Hierarchy

Svep för att visa menyn

Uppgift

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).

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 10
some-alt