Loading

Quipoin Menu

Learn • Practice • Grow

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

Q1.

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

Q2.

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

Q3.

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

Q4.

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

Q5.

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

Q6.

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

Q7.

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 does not receive any special first argument
D. Define a method that cannot be overridden
Direction: Choose the correct option

Q8.

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

Q9.

What is inheritance in Python?
A. A way to create multiple objects
B. A type of encapsulation
C. A method overloading
D. A mechanism to create a new class from an existing class
Direction: Choose the correct option

Q10.

How do you define class B that inherits from class A?
A. class B inherits A:
B. class B = A:
C. class B(A):
D. class B extends A: