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

Question 26

Consider the following Python class:



If you instantiate two objects of this class and modify the base attribute using the modify_base class method in one of the instances, what will be the output when you print the base attribute of both instances?

  • A

    Only the base attribute of the instance where the class method was called will reflect the new value.

  • B

    The base attribute of both instances will reflect the new value.

  • C

    The base attribute of both instances will remain unchanged.

  • D

    The base attribute of the instance where the class method was not called will reflect the new value.

Reveal correct answer

Correct answer: B

A.

@classmethod modifies the class attribute, not just the attribute of a specific instance.

B.

This is correct because the @classmethod decorator allows the method to modify class state that applies across all instances of the class.

C.

The modify_base method is designed to modify the base attribute of the class.

D.

This is incorrect because the @classmethod modifies the class state and not just specific instance state.

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