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 Python?

View

How is data hiding achieved in Python?

View

What does the following code do?

View

Which is an example of public access in Python?

View

What is the correct way to access a private attribute outside the class?

View

Which keyword allows indirect access to private attributes?

View

What does the following code output?

View

Which of the following statements is true about protected members?

View

What is the primary purpose of data hiding?

View

Which principle of OOP does encapsulation support?

View

What is encapsulation in Python?

Grouping variables and functions into a module
Bundling data and methods within a class
Restricting access to public methods
Overriding parent class methods

How is data hiding achieved in Python?

Using the @property decorator
By making attributes private using a double underscore prefix
By declaring variables as global
Using self keyword in constructors

What does the following code do?

class A: def __init__(self): self.__hidden = 10 obj = A() print(obj.__hidden)

Prints 10
Raises an AttributeError
Prints None
Prints __hidden

Which is an example of public access in Python?

self.__data
self._data
self.data
self.___data

What is the correct way to access a private attribute outside the class?

Use the super() method
Use the @staticmethod decorator
Access it using _ClassName__attribute
Access it directly as object.__attribute

Which keyword allows indirect access to private attributes?

super()
setter
getter
private

What does the following code output?

class A: def __init__(self): self._data = "Protected" obj = A() print(obj._data)

Error
Protected
None
Private

Which of the following statements is true about protected members?

They can only be accessed within the class
They cannot be inherited
They are prefixed with a single underscore (_)
They can only be accessed through methods

What is the primary purpose of data hiding?

To prevent access to private classes
To ensure data security and prevent unauthorized access
To allow multiple inheritances
To implement operator overloading

Which principle of OOP does encapsulation support?

Polymorphism
Inheritance
Abstraction
Encapsulation