LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Find the Error · Question 1

Error: creating an object of an abstract class Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

The program below stops with an error. Which statement correctly describes the problem?

main.py
from abc import ABC, abstractmethod

class Vehicle(ABC):
    @abstractmethod
    def wheels(self):
        ...

v = Vehicle()
print(v.wheels())
  • A TypeError: Vehicle has an abstract method, so it cannot be instantiated; create a subclass that implements wheels() Correct
  • B It prints None
  • C NotImplementedError
  • D AttributeError
Correct Answer: Option A

Abstract base classes exist to be subclassed.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links