Python Programming (2180711) MCQs

MCQs of Classes and Object-Oriented Programming

Showing 1 to 10 out of 45 Questions
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
Answer:

Option (b)

2.
_____ is used to create an object.
(a) class
(b) constructor
(c) user-defined functions
(d) In-built functions
Answer:

Option (b)

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
Answer:

Option (c)

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
Answer:

Option (b)

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
Answer:

Option (a)

6.
What is Instantiation in terms of OOP terminology?
(a) Deleting an instance of class
(b) Modifying an instance of class
(c) Copying an instance of class
(d) Creating an instance of class
Answer:

Option (d)

7.
What will be the output of the following Python code?
class fruits:
    def __init__(self, price):
        self.price = price
obj=fruits(50)
 
obj.quantity=10
obj.bags=2
 
print(obj.quantity+len(obj.__dict__))
(a) 12
(b) 52
(c) 13
(d) 60
Answer:

Option (c)

8.
The assignment of more than one function to a particular operator is _______
(a) Operator over-assignment
(b) Operator overriding
(c) Operator overloading
(d) Operator instance
Answer:

Option (c)

9.
Which of the following is not a class method?
(a) Non-static
(b) Static
(c) Bounded
(d) Unbounded
Answer:

Option (a)

10.
Which of the following Python code creates an empty class?
(a)
class A:
    return
(b)
class A:
    pass
(c)
class A:
(d) It is not possible to create an empty class
Answer:

Option (b)

Showing 1 to 10 out of 45 Questions