Loading

Quipoin Menu

Learn • Practice • Grow

Direction: Choose the correct option

Q1.

What is encapsulation in OOP?
A. Bundling data and methods within an object and restricting access
B. Inheritance of properties
C. Method overloading
D. Polymorphic behavior
Direction: Choose the correct option

Q2.

How do you create a private attribute in Python?
A. Prefix with double underscore `__`
B. Use `protected` keyword
C. Prefix with single underscore `_`
D. Use `private` keyword
Direction: Choose the correct option

Q3.

What is name mangling?
A. It encrypts the variable
B. It deletes the variable
C. It removes underscores
D. Python renames `__var` to `_ClassName__var` to avoid accidental access
Direction: Choose the correct option

Q4.

What does a single underscore prefix `_var` conventionally indicate?
A. A protected/internal variable (convention)
B. A public variable
C. A private variable (enforced)
D. A special method
Direction: Choose the correct option

Q5.

How can you access a mangled attribute `__name` from outside the class?
A. obj.__name
B. obj._name
C. obj._ClassName__name
D. obj.__name__
Direction: Choose the correct option

Q6.

What is the purpose of getter and setter methods?
A. To print values
B. To delete attributes
C. To create new attributes
D. To control access to private attributes
Direction: Choose the correct option

Q7.

How do you define a property using the `@property` decorator?
A. `@getter` decorator
B. `@property` followed by a method; getter is the method name
C. `@attribute`
D. `@property` on an attribute
Direction: Choose the correct option

Q8.

What does `@property` achieve?
A. Allows methods to be accessed like attributes
B. Makes an attribute private
C. Both A and C
D. Creates a read-only property
Direction: Choose the correct option

Q9.

What is the difference between `_var` and `__var`?
A. `_var` is a convention for protected; `__var` triggers name mangling
B. `__var` is public
C. `_var` is private
D. They are the same
Direction: Choose the correct option

Q10.

Can we access `__var` from outside the class directly?
A. Yes, directly
B. Only if it's defined as property
C. No, but it can be accessed via `_ClassName__var`
D. No, never