PCPP 32 10x PCPP Certified Professional Python Programmer 1 · Free Practice Question Medium

Question 18

What is the result of the following code?



  • A

    This code is erroneous. It will raise the TypeError exception.

  • B

    This code is erroneous. It will raise the AttributeError exception.

  • C
  • D
Reveal correct answer

Correct answer: C

A.

This would happen if the Square class didn't implement the abstract methods area() and perimeter() from the Figure class. However, since Square does implement both methods, no TypeError is raised. This answer is incorrect.

B.

An AttributeError would be raised if we tried to access an attribute or method that does not exist. Since all required methods and attributes are correctly defined, this error does not occur. This answer is incorrect.

C.

This is the correct answer. The area() method returns 100, and the perimeter() method returns 40.

D.

This would be the output if the Square instance was created with the default value of a = 1. However, since Square(10) is used, this answer is incorrect.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need