Faruk Hasan

Faruk Hasan

Software QA Engineer | Automation & AI-Driven Testing Specialist

šŸ Python OOP Quiz 2

1. What is the main purpose of OOP?

2. Which of the following is used to create a class?

3. Which method is the constructor in Python?

4. What does self refer to in a class method?

5. What is inheritance used for?

6. You can have more than one constructor in a Python class. (True/False)

7. Private attributes in Python start with a single underscore _ . (True/False)

8. Python supports multiple inheritance. (True/False)

9. A class method can be called without creating an object. (True/False)

10. @staticmethod allows access to the class variables. (True/False)

11. What will be the output of this code?

class Animal:
    def __init__(self, name):
        self.name = name
    def speak(self):
        return self.name + " says hello"

dog = Animal("Buddy")
print(dog.speak())

12. What is the error in this code?

class Car:
    def start_engine():
        print("Engine started")

my_car = Car()
my_car.start_engine()

13. Fill in the blank to complete this method:

def ________:
    return self.first + " " + self.last

14. What is the difference between a class variable and an instance variable?

15. You have a base class Shape and a subclass Circle. What would you do to ensure that Circle also has the __init__ method from Shape?