WorksheetsQuiz 05 - Python Objects
Total questions: 22
Worksheet time: 5mins
1. What is a class in in Python?
a) A variable that holds data
b) A template for creating objects
c) A built-in function
d) A type of loop
2. Which method is automatically called when an object is created?
a) __del__
b) __main__
c) __init__
d) __str__
3. What does self represent in a class method?
a) The parent class
b) The instance of the class
c) A reserved keyword for inheritance
d) A reference to the class itself
4. Which keyword is used to inherit from a parent class?
a) extends
b) inherit
c) super
d) Parentheses in the class definition
5. What is the output of the code below? print(type([]))
a)
b)
c)
d)
6. Which statement about instance attributes is true?
a) They are shared across all instances of a class.
b) They are defined outside the __init__ method.
c) They are unique to each object.
d) They cannot be modified after creation.
7. What does the dir(obj) function return?
a) The documentation string of obj
b) A list of obj’s attributes and methods
c) The memory address of obj
d) The parent class of obj
8. Which code correctly creates an instance of a class Dog?
a) Dog.create()
b) Dog.__init__()
c) Dog()
d) new Dog()
9. What is the purpose of a destructor (__del__)?
a) Initialize object attributes
b) Delete an object’s methods
c) Clean up resources before an object is destroyed
d) Prevent inheritance
10. Which class definition demonstrates inheritance?
a) class Car: pass
b) class Tesla(Car): pass
c) class Engine: pass
d) class Car(Tesla): pass
11. A class can have multiple constructors in Python
True
False
12. Instance attributes override class attributes with the same name
True
False
13. The __del__ method is commonly used in production code
True
False
14. All methods in a class must include self as the first parameter.
True
False
15. Inheritance allows a subclass to inherit private attributes from its parent
True
False
16. The (a) method is used to initialize an object’s state.
17. Write the syntax for creating a subclass Dog inheriting from class Animal.
(a)
18. What does the following code output?
(a)
19. The function (a) lists all attributes and methods of an object.
20. Write the command to check the capabilities (methods and attributes) of an object obj.
(a)
