Python Class Quiz – 15 Questions

If you’re learning Python and want to test your understanding of Python classes you are in the right place, this quiz is perfect for you. Classes are the building blocks of object-oriented programming in Python, helping you organize code into reusable structures. In this Python Class Quiz – 15 Questions, you’ll get a chance to solve beginner-to-intermediate level problems that focus on creating classes, initializing objects, using methods, inheritance, and more. By the end, you’ll know exactly which areas you’ve mastered and where you need more practice.

Python Class Quiz


Things Covered in This Quiz

In this quiz, you’ll practice and improve your skills in:

  • Defining Python classes and creating objects
  • Using __init__ constructors
  • Working with instance and class variables
  • Writing and calling class methods
  • Understanding inheritance and method overriding
  • Using built-in class functions like __str__
  • Applying @staticmethod and @classmethod decorators


1. What is the correct way to define a class in Python?

class MyClass:
    pass

2. What does the __init__ method do in a class?

3. What will be the output?

class Test:
    def __init__(self):
        print("Hello World")

obj = Test()

4. How do you create an object of a class named Student?

5. What will this print?

class MyClass:
    def greet(self):
        return "Hi!"

obj = MyClass()
print(obj.greet())

6. Which keyword is used for inheritance in Python?

7. What will be the output?

class Car:
    wheels = 4

print(Car.wheels)

8. What does the @staticmethod decorator do?

9. Which is correct to define a class variable?

10. Output?

class A:
    def __str__(self):
        return "Class A"

obj = A()
print(obj)

11. What will happen?

class Test:
    pass

print(isinstance(Test(), Test))

12. How do you call a parent class method in a child class?

13. What is true about __del__?

14. Which is correct for multiple inheritance?

15. Which is true about instance methods?


Conclusion

You’ve now completed the Python Class Quiz – 15 Questions and tested your skills on the fundamentals of Python classes. If you scored high, great job — you’re ready to tackle more advanced OOP concepts like polymorphism, abstraction, and design patterns. If you missed a few, revisit those topics, experiment with more examples, and keep practicing.

Post a Comment

Previous Post Next Post