CommerceClasses And Objects In Python MCQs
Practice Classes And Objects In Python MCQs for competitive exams.
Classes And Objects In Python MCQs
Practice questions from this topic.
What are the methods which begin and end with two underscore characters called?
- A. Special methods
- B. In-built methods
- C. User-defined methods
- D. Additional methods
Correct Answer: A
. . . . . . . . is used to create an object.
- A. class
- B. constructor
- C. User-defined functions
- D. In-built functions
Correct Answer: B
. . . . . . . . represents an entity in the real world with its identity and behaviour.
- A. A method
- B. An object
- C. A class
- D. An operator
Correct Answer: B
How can you access a class variable in Python?
- A. Using the class name and dot notation
- B. Using the self keyword
- C. Using the cls keyword
- D. Using the object keyword
Correct Answer: A
What is the difference between a class variable and an instance variable in Python?
- A. A class variable is shared among all instances of a class, while an instance variable is unique to each instance
- B. They are the same
- C. An instance variable is shared among all instances
- D. A class variable is unique to each instance
Correct Answer: A
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
Correct Answer: C
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
Correct Answer: D
Which operator is overloaded by __lg__()?
- A. <
- B. >
- C. !=
- D. none of the mentioned
Correct Answer: D
Which operator is overloaded by __invert__()?
- A. !
- B. ~
- C. ^
- D. -
Correct Answer: B
Which function is called when the following Python code is executed? f = foo() format(f)
- A. format()
- B. __format__()
- C. str()
- D. __str__()
Correct Answer: D
What is the purpose of the __del__ method in Python classes?
- A. It is called when an object is about to be destroyed
- B. It deletes an object
- C. It defines a destructor
- D. It is a constructor
Correct Answer: A
What is the purpose of the __str__ method in Python classes?
- A. It returns a string representation of an object
- B. It converts an object to a string
- C. It defines a string attribute
- D. It removes an attribute
Correct Answer: A