Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quizz Day 1 Python OO

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.
Encapsulation in OOP means
a)
Hiding data behind interfaces
b)
Bundling data and methods in a class
c)
Copying data between classes
d)
Encrypting attributes
2.
The main goal of encapsulation is
a)
Code reuse
b)
Data hiding and integrity
c)
Speed
d)
Abstraction
3.
Inheritance allows a class to
a)
Create new variables only
b)
Reuse and extend behavior of another class
c)
Hide its implementation
d)
Access private attributes
4.
Polymorphism means
a)
One object can belong to many modules
b)
Same method behaves differently for different objects
c)
Multiple inheritance is used
d)
Same variable type for all classes
5.
Abstraction provides
a)
Implementation details
b)
A common interface without details
c)
A private class
d)
Class duplication
6.
Multiple inheritance allows
a)
A child to inherit from one parent only
b)
A child to inherit from several parents
c)
To use private attributes
d)
None of these
7.
The MRO (Method Resolution Order) defines
a)
The order of variable initialization
b)
The order of method lookup
c)
The import order
d)
None of the above
8.
Python uses which algorithm for MRO?
a)
Dijkstra
b)
Bellman-Ford
c)
C3 Linearization
d)
DFS
9.
The diamond problem arises when
a)
Classes have identical names
b)
Two parents share a common ancestor
c)
Methods have same name
d)
Multiple attributes overlap
10.
The C3 linearization ensures the MRO is
a)
Random
b)
Monotonic, consistent, unambiguous
c)
Static
d)
Parent-first always
11.
In MRO, declaration order of parents
a)
Doesn’t matter
b)
Directly affects lookup order
c)
Is alphabetic
d)
Is always ignored
12.
Abstract Base Classes are used to
a)
Prevent inheritance
b)
Define a contract for subclasses
c)
Store data only
d)
Create anonymous classes
13.
An abstract class can be instantiated
a)
Yes
b)
Only once
c)
Only via metaclasses
d)
No
14.
The decorator marking an abstract method is
a)
@staticmethod
b)
@classmethod
c)
@abstractmethod
d)
@dataclass
15.
Template Method pattern defines
a)
Steps of an algorithm in base class
b)
Random inheritance
c)
Factory logic
d)
Multiple constructors
16.
The advantage of Template Method pattern is
a)
Complete freedom
b)
No hierarchy
c)
Uniform process with flexibility
d)
Multiple constructors
17.
The @dataclass decorator
a)
Adds abstract methods
b)
Automatically generates boilerplate code
c)
Creates a JSON schema
d)
Disables inheritance
18.
Dataclasses automatically generate
a)
init, repr, eq, str
b)
init, call, len, repr
c)
Only init
d)
Only str
19.
The post_init() method is called
a)
Before init
b)
After init
c)
Instead of init
d)
Randomly
20.
frozen=True makes a dataclass
a)
Immutable
b)
Mutable
c)
Faster
d)
Larger
21.
Trying to modify a frozen dataclass field raises
a)
KeyError
b)
ValueError
c)
FrozenInstanceError
d)
TypeError
22.
field(default_factory=...) is used for
a)
Default static values
b)
Mutable default values safely
c)
Abstract defaults
d)
None
23.
Using {} as default for a dict field in dataclass is
a)
Recommended
b)
Problematic
c)
Mandatory
d)
Irrelevant
24.
Lambda functions are
a)
Named reusable functions
b)
Anonymous short functions
c)
Abstract base classes
d)
Static methods
25.
Syntax of a lambda is
a)
lambda args: expression
b)
def: expression
c)
def lambda():
d)
func: lambda
26.
Lambda functions are ideal for
a)
Long algorithms
b)
One-off small operations
c)
Database setup
d)
Class inheritance
27.
filter() keeps elements where
a)
Function returns True
b)
Function returns False
c)
Index > 0
d)
None
28.
map() is used to
a)
Filter lists
b)
Transform all elements
c)
Sort items
d)
Print data
29.
sorted(iterable, key=function)
a)
Sorts by lambda key
b)
Filters data
c)
Maps objects
d)
Returns a dict
30.
reverse=True in sorted()
a)
Sorts ascending
b)
Sorts descending
c)
Randomizes
d)
No effect