Python Programming Multiple Choice Question -
Classes and Objects

This section focuses on the "Classes and Objects" in Python programming. These Multiple Choice Questions (mcq) should be practiced to improve the Python programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. To create a class, use the keyword?

A. new
B. except 
C. class
D. object

View Answer


2. All classes have a function called?

A. __init__
B. __init__()
C. init
D. init()

View Answer


3. The __________ parameter is a reference to the current instance of the class, and is used to access variables that belong to the class.

A. __init__()
B. self
C. both A and B
D. None of the above

View Answer


4. You can delete properties on objects by using the ______ keyword.

A. delete
B. dedl
C. del
D. drop

View Answer


5. A variable that is defined inside a method and belongs only to the current instance of a class is known as?

A. Inheritance 
B. Instance variable
C. Function overloading
D. Instantiation 

View Answer


6. A class variable or instance variable that holds data associated with a class and its object is known as?

A. Class variable
B. Method 
C. Operator overloading
D. Data member

View Answer


7. What is setattr() used for?

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

View Answer


8. What will be output for the folllowing code?

 class test:
     def __init__(self,a):
         self.a=a
 
     def display(self):
         print(self.a)
obj=test()
obj.display()

A. Runs normally, doesn’t display anything
B. Displays 0, which is the automatic default value
C. Error as one argument is required while creating the object
D. Error as display function requires additional argument

View Answer


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

A. A method
B. An object
C. A class
D. An operator

View Answer


10. The class has a documentation string, which can be accessed via?

A. ClassName
B. ClassName __doc__
C. __doc__
D. ClassName.__doc__

View Answer




Discussion



* You must be logged in to add comment.

Mohamd Maksoud
perfect