Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is encapsulation?

View

Which symbol denotes a private attribute?

View

Which of the following is a public attribute?

View

What does the following code do?

View

How do you access a private attribute from outside a class?

View

What type of attribute is _name?

View

Which method is a setter method?

View

What is the purpose of setter methods?

View

Which of the following keywords ensures read-only attributes?

View

How do you create a protected attribute?

View

What is encapsulation?

Binding data with code
Defining private attributes only
Inheriting from multiple classes
Separating class definitions

Which symbol denotes a private attribute?

_
__
$
!

Which of the following is a public attribute?

self.__name
self._name
name
All of the above

What does the following code do?

class Student: def __init__(self): self.__name = "John" def get_name(self): return self.__name

Raises an error
Creates a public attribute
Implements a getter method
Prevents access to __name

How do you access a private attribute from outside a class?

Directly using self.attribute
Using _ClassName__attribute
With object.attribute
It’s not possible

What type of attribute is _name?

Private
Protected
Public
Constant

Which method is a setter method?

__setattr__()
def set_value(self, value):
def get_value(self):
def __getattr__()

What is the purpose of setter methods?

To update attributes securely
To access private attributes
To initialize objects
To prevent inheritance

Which of the following keywords ensures read-only attributes?

final
const
property
readonly

How do you create a protected attribute?

Use self.attribute
Use self._attribute
Use self.__attribute
None of the above