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 in OOP?

View

Which symbol is used to make an attribute private?

View

What happens if you try to access a private attribute directly?

View

Which method is used to access private attributes in a class?

View

What is the purpose of the @property decorator?

View

How do you make an attribute "read-only"?

View

What will be the output of accessing _name attribute directly?

View

Which of the following defines encapsulation accurately?

View

What does the term “data hiding” refer to?

View

How does Python indicate that a variable is intended for internal use only?

View

What is encapsulation in OOP?

Keeping all methods private
Wrapping code and data into a single unit
Allowing multiple inheritance
Breaking large programs into smaller functions

Which symbol is used to make an attribute private?

#
__ (double underscore)
_ (single underscore)
@

What happens if you try to access a private attribute directly?

It raises a ValueError
The attribute will be hidden, raising an AttributeError
The program will ignore it
The interpreter converts it to public automatically

Which method is used to access private attributes in a class?

Setter method
__del__() method
Getter method
init() method

What is the purpose of the @property decorator?

To protect public methods
To create getters for private attributes
To call private methods
To initialize attributes

How do you make an attribute "read-only"?

Use the @staticmethod decorator
Define a getter without a setter
Declare it with __read__
Use a final keyword

What will be the output of accessing _name attribute directly?

class Person: def __init__(self, name): self._name = name p = Person("Alice") print(p._name)

AttributeError
None
Alice
private attribute

Which of the following defines encapsulation accurately?

Data hiding with no access
Providing controlled access to data
Data protection with global variables
Using only public methods in classes

What does the term “data hiding” refer to?

Preventing data from being accessed
Restricting access to attributes outside the class
Using only constants in methods
Encrypting attributes of a class

How does Python indicate that a variable is intended for internal use only?

By prefixing the variable with __
By using self
By using final keyword
By setting the variable as global