Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is a constructor in Python?

View

What is the name of the constructor method in Python?

View

Which method is called when an object is destroyed?

View

When is the destructor method (__del__) automatically called?

View

Can a class have multiple constructors in Python?

View

What happens if super().__init__() is not called in a child class?

View

What is the output of this code?

View

What is the purpose of super() in constructors?

View

Which of these statements about destructors is true?

View

Can you call a destructor explicitly in Python?

View

What is a constructor in Python?

A method to delete an object
A method that initializes an object when it's created
A method to compare two objects
A method used for polymorphism

What is the name of the constructor method in Python?

__create__
__start__
__init__
__construct__

Which method is called when an object is destroyed?

__delete__
__destroy__
__del__
__clear__

When is the destructor method (__del__) automatically called?

When the object is no longer referenced
When the program starts
When the object is created
When the super() function is called

Can a class have multiple constructors in Python?

Yes, using function overloading
No, only one constructor is allowed
Yes, using class methods
Only in built-in classes

What happens if super().__init__() is not called in a child class?

Parent class attributes will not be initialized
The child class will fail to compile
It raises a TypeError
It affects only public methods

What is the output of this code?

class A: def __init__(self): print("A initialized") class B(A): def __init__(self): print("B initialized") super().__init__() b = B()

A initialized
B initialized
B initialized A initialized
Error

What is the purpose of super() in constructors?

To call the destructor
To initialize attributes from the parent class
To prevent multiple inheritance
To manage private attributes

Which of these statements about destructors is true?

Destructors must always be manually invoked
Destructors are called when the program terminates
Destructors are called when objects are garbage collected
Destructors run after __init__() completes

Can you call a destructor explicitly in Python?

No, it is only invoked automatically
Yes, using the __del__() method
Only with the super() function
Only in abstract classes