Python Programming (2180711) MCQ

MCQs of Classes and Object-Oriented Programming

MCQ No - 1

_____ represents an entity in the real world with its identity and behavior.

(A) A method
(B) An object
(C) A class
(D) An operator

B
MCQ No - 2

_____ is used to create an object.

(A) class
(B) constructor
(C) user-defined functions
(D) In-built functions

B
MCQ No - 3

What will be the output of the following Python code?
class test:
     def __init__(self,a=""Hello World""):
         self.a=a
 
     def display(self):
         print(self.a)
obj=test()
obj.display()

(A) The program has an error because constructor can’t have default arguments
(B) Nothing is displayed
(C) “Hello World” is displayed
(D) The program has an error display function doesn’t have parameters

C
MCQ No - 4

What is setattr() used for?

(A) To access the attribute of the object
(B) To set an attribute
(C) To check if an attribute exists or not
(D) To delete an attribute

B
MCQ No - 5

What is getattr() used for?

(A) To access the attribute of the object
(B) To delete an attribute
(C) To check if an attribute exists or not
(D) To set an attribute

A