Commerce

Classes 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?

  1. A. Special methods
  2. B. In-built methods
  3. C. User-defined methods
  4. D. Additional methods
Report Error

. . . . . . . . is used to create an object.

  1. A. class
  2. B. constructor
  3. C. User-defined functions
  4. D. In-built functions
Report Error

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

  1. A. A method
  2. B. An object
  3. C. A class
  4. D. An operator
Report Error

How can you access a class variable in Python?

  1. A. Using the class name and dot notation
  2. B. Using the self keyword
  3. C. Using the cls keyword
  4. D. Using the object keyword
Report Error

What is the difference between a class variable and an instance variable in Python?

  1. A. A class variable is shared among all instances of a class, while an instance variable is unique to each instance
  2. B. They are the same
  3. C. An instance variable is shared among all instances
  4. D. A class variable is unique to each instance
Report Error

The assignment of more than one function to a particular operator is . . . . . . . .

  1. A. Operator over-assignment
  2. B. Operator overriding
  3. C. Operator overloading
  4. D. Operator instance
Report Error

What is Instantiation in terms of OOP terminology?

  1. A. Deleting an instance of class
  2. B. Modifying an instance of class
  3. C. Copying an instance of class
  4. D. Creating an instance of class
Report Error

Which operator is overloaded by __lg__()?

  1. A. <
  2. B. >
  3. C. !=
  4. D. none of the mentioned
Report Error

Which operator is overloaded by __invert__()?

  1. A. !
  2. B. ~
  3. C. ^
  4. D. -
Report Error

Which function is called when the following Python code is executed? f = foo() format(f)

  1. A. format()
  2. B. __format__()
  3. C. str()
  4. D. __str__()
Report Error

What is the purpose of the __del__ method in Python classes?

  1. A. It is called when an object is about to be destroyed
  2. B. It deletes an object
  3. C. It defines a destructor
  4. D. It is a constructor
Report Error

What is the purpose of the __str__ method in Python classes?

  1. A. It returns a string representation of an object
  2. B. It converts an object to a string
  3. C. It defines a string attribute
  4. D. It removes an attribute
Report Error