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 modifier makes an attribute private?

View

What is the main benefit of encapsulation?

View

How do you access a private attribute?

View

What does self refer to in a class method?

View

What is the purpose of a setter method?

View

What is the output of this code?

View

Which of these best describes encapsulation?

View

Can encapsulation be achieved without using private variables?

View

What is the difference between a public and private attribute?

View

What is encapsulation?

Making attributes accessible to everyone
Binding data and methods together into a single unit
Preventing inheritance
Hiding attributes without methods

Which modifier makes an attribute private?

_
__
@staticmethod
self

What is the main benefit of encapsulation?

Prevents memory leaks
Protects data from unauthorized access
Makes code run faster
Allows multiple inheritance

How do you access a private attribute?

Using a getter method
Using the @staticmethod decorator
Directly using self.__attribute
Using @classmethod

What does self refer to in a class method?

The parent class
The instance of the class calling the method
A static reference to the class
The method itself

What is the purpose of a setter method?

To delete private attributes
To update or modify a private attribute
To prevent attribute changes
To convert methods to static methods

What is the output of this code?

class Student: def __init__(self, name): self.__name = name def get_name(self): return self.__name s = Student("Alice") print(s.get_name())

Error
None
Alice
__name

Which of these best describes encapsulation?

Public access to all data
Restricted access to certain data
Multiple inheritance
Abstract classes only

Can encapsulation be achieved without using private variables?

Yes
No
Only with abstract classes
Only with inheritance

What is the difference between a public and private attribute?

Public attributes are accessible anywhere, private ones are not
Private attributes are faster
Public attributes are immutable
Private attributes must be defined with @property