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

How do you denote private attributes in Python?

View

What is the main benefit of encapsulation?

View

What will the following code output?

View

How can you access a private variable outside a class?

View

What will this code print?

View

What is the difference between _var and __var in Python?

View

Which access modifier does Python lack?

View

Which of the following correctly defines a protected attribute?

View

Which of the following statements is true?

View

What is encapsulation in OOP?

Binding variables and methods together in a class
Hiding the class constructor
Overriding methods from a parent class
Allowing multiple instances of a class

How do you denote private attributes in Python?

With a trailing underscore (e.g., var_)
With two leading underscores (e.g., __var)
Using the private keyword
With a single underscore (e.g., _var)

What is the main benefit of encapsulation?

Code reusability
Protecting sensitive data
Faster method execution
Reducing memory usage

What will the following code output?

class A: def __init__(self): self.__x = 5 obj = A() print(obj.__x)

5
None
Error
0

How can you access a private variable outside a class?

Using private() function
Using the dir() function
Through name mangling (_ClassName__var)
By importing the encapsulation module

What will this code print?

class A: def __init__(self): self.__x = 10 def get_value(self): return self.__x obj = A() print(obj.get_value())

10
None
Error
0

What is the difference between _var and __var in Python?

Both indicate private attributes
_var is a convention; __var enforces name mangling
Both are used for global variables
No difference between them

Which access modifier does Python lack?

Private
Protected
Public
Final

Which of the following correctly defines a protected attribute?

self.__x = 10
self._x = 20
x = 30
private self.x = 40

Which of the following statements is true?

Private attributes cannot be accessed at all from outside the class.
Protected attributes are intended to be accessible only by subclasses.
Public attributes cannot be accessed directly.
Encapsulation prevents method overriding.