Loading

Quipoin Menu

Learn • Practice • Grow

python / Classes and Objects
mcq
Direction: Choose the correct option

Q1.

What is a class in Python?
A. A function
B. A blueprint for creating objects
C. A module
D. A data type
Direction: Choose the correct option

Q2.

How do you create an object (instance) of a class `MyClass`?
A. obj = new MyClass()
B. obj = MyClass()
C. obj = MyClass
D. obj = class MyClass
Direction: Choose the correct option

Q3.

What is the `__init__` method used for?
A. Class method
B. Constructor to initialize object attributes
C. Static method
D. Destructor
Direction: Choose the correct option

Q4.

What is `self` in a class method?
A. The method's return value
B. A keyword
C. Reference to the class
D. Reference to the current instance
Direction: Choose the correct option

Q5.

How do you define a method inside a class?
A. function method(self):
B. def self.method():
C. def method(self):
D. def method():
Direction: Choose the correct option

Q6.

What is the output of `class A: x=5; print(A.x)`?
A. 5
B. <A object>
D. Error
Direction: Choose the correct option

Q7.

How do you access an instance variable from within a method?
A. self[variable]
B. self.variable
C. variable
D. self.variable
Direction: Choose the correct option

Q8.

What is the purpose of `@classmethod`?
A. Define a method that receives the instance
B. Define a property
C. Define a static method
D. Define a method that receives the class as first argument
Direction: Choose the correct option

Q9.

What is the purpose of `@staticmethod`?
A. Define a method that receives `cls`
B. Define a method that receives `self`
C. Define a method that cannot be overridden
D. Define a method that does not receive any special first argument
Direction: Choose the correct option

Q10.

What does `isinstance(obj, MyClass)` do?
A. Returns the class of obj
B. Checks if obj is an instance of MyClass
C. Checks if obj equals MyClass
D. Raises error