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

Which keyword is used to access a private attribute of a class from outside?

View

How can a protected attribute be identified?

View

What is the default access modifier for class attributes in Python?

View

Which of the following is an example of a protected attribute?

View

What will be the output of the following code?

View

How do you change the value of a private attribute?

View

What is the purpose of getter and setter methods?

View

Which of the following best describes data hiding?

View

Which access modifier should be used to allow a variable to be accessed only within the same class?

View

What will be the output of accessing a protected attribute directly?

View

Which keyword is used to access a private attribute of a class from outside?

self
super()
_ClassName__attribute
object

How can a protected attribute be identified?

Prefix with __
Suffix with _protected
Prefix with _
Use a special decorator

What is the default access modifier for class attributes in Python?

Private
Protected
Public
Static

Which of the following is an example of a protected attribute?

__salary
salary
_salary
@salary

What will be the output of the following code?

class Employee: def __init__(self, name, salary): self.__salary = salary emp = Employee("John", 5000) print(emp.__salary)

5000
None
AttributeError
0

How do you change the value of a private attribute?

Use the @property decorator
Use a setter method
Directly access it using __
It cannot be modified

What is the purpose of getter and setter methods?

To modify protected attributes only
To control access to class attributes
To avoid using constructors
To restrict object creation

Which of the following best describes data hiding?

Making all methods private
Restricting access to some attributes from outside the class
Hiding the entire class from other modules
Making the object immutable

Which access modifier should be used to allow a variable to be accessed only within the same class?

Public
Protected
Private
Final

What will be the output of accessing a protected attribute directly?

class Car: def __init__(self): self._brand = "Tesla" c = Car() print(c._brand)

AttributeError
None
Tesla
0