Courseiva
Object-Oriented Programming →mediumMultiple Select

PCAP Object-Oriented Programming Practice Question

Which TWO of the following statements about Python classes are true? (Select exactly 2.)

⚠ Common exam trap

Python Institute often tests the misconception that __init__ is the constructor (it is actually __new__) and that double-underscore attributes are truly private (they are only name-mangled, not inaccessible).

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Class variables are shared among all instances.

Class variables are defined directly in the class body and are shared across all instances of that class. When you modify a class variable through the class itself, the change is reflected in every instance, as the variable is stored in the class's __dict__ rather than in each instance's __dict__.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Class names should be written in snake_case per PEP 8.

    Why it's wrong here

    PEP 8, the official Python style guide, specifies that class names should use CapWords (also called CamelCase) notation, such as MyClass, not snake_case. snake_case is reserved for function names, variables, and module attributes. Using snake_case for a class name violates the widely accepted convention and reduces readability for other Python developers.

  • ✓

    Class variables are shared among all instances.

    Why this is correct

    Class variables are bound to the class namespace rather than to individual instances, so every instance shares the same variable. If the variable is reassigned on an instance, that creates a separate instance-level attribute that shadows the shared class variable, but the class variable itself remains unchanged for other instances. This shared behavior is a fundamental distinction from instance attributes, which are defined inside __init__ or other methods.

  • ✗

    Private attributes (starting with __) cannot be accessed outside the class.

    Why it's wrong here

    Attributes with double leading underscores are not truly private; they are name-mangled at compile time to _ClassName__attribute to prevent accidental name collisions in subclasses. This mangling is deterministic and can be circumvented by referencing the mangled name from outside the class. Therefore, saying they cannot be accessed at all is false—they are simply hidden by convention and transformation.

  • ✗

    __init__ is the constructor of a class.

    Why it's wrong here

    In Python, __init__ is the instance initializer, not the constructor, because it is called after the instance object already exists. The actual constructor is __new__, a static method that allocates and returns a new instance; __init__ then receives that instance to set up its state. Mislabeling __init__ as the constructor overlooks the distinct roles these two methods play in object creation.

  • ✓

    Instance methods must have 'self' as the first parameter.

    Why this is correct

    Instance methods are defined inside a class and automatically receive the instance as their first argument; by convention this parameter is named self, but the name itself is not syntactically required. When you call obj.method(...), Python passes obj as the first argument to the method, so it must be able to access the instance's attributes. This is what distinguishes an instance method from a static method, which receives no automatic instance reference.

About these practice questions

One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.