Python OOP Basics Quiz
A 35-question quiz covering the fundamentals of Object-Oriented Programming in Python, including classes, objects, attributes, and methods.
Question 1
Which keyword is used to define a class in Python?
Question 2
What is the correct syntax to define an empty class named `Robot`?
# Option A
class Robot:
pass
# Option B
def Robot():
return
# Option C
class Robot {}
# Option D
new class Robot:
Question 3
What is the standard naming convention for Python classes?
Question 4
Which of the following best describes a 'class' in Python?
Question 5
What happens if you define a class without a body (no code indented under it)?
class MyClass:
# No code here
Question 6
What is the purpose of the docstring inside a class definition?
class User:
"""Represents a system user."""
pass
Question 7
Which method is automatically called when a new object is instantiated?
Question 8
What will this code output?
class Cat:
def __init__(self):
print("Meow")
c = Cat()
Question 9
What is the primary purpose of the `__init__` method?
Question 10
How do you correctly pass arguments to the constructor?
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
# Instantiation
Question 11
What is wrong with this constructor definition?
class Dog:
def __init__(name):
self.name = name
Question 12
Can `__init__` return a value other than `None`?
Question 13
How do you access an instance attribute named `color` inside a method?
Question 14
What will be printed?
class Box:
def __init__(self, size):
self.size = size
b = Box(10)
print(b.size)
Question 15
Instance attributes are...
Question 16
What happens here?
class Player:
def __init__(self, name):
self.name = name
p1 = Player("Alice")
p2 = Player("Bob")
p1.name = "Charlie"
print(p2.name)
Question 17
Can you add new attributes to an object after it has been created?
class Car:
pass
c = Car()
c.wheels = 4
print(c.wheels)
Question 18
What is the correct way to delete an instance attribute?
Question 19
Where are class attributes defined?
Question 20
What is the output?
class Dog:
species = "Canine"
d1 = Dog()
d2 = Dog()
print(d1.species)
Question 21
What happens when you modify a class attribute via an instance?
class A:
x = 10
a = A()
a.x = 20
print(A.x)
Question 22
How should you modify a class attribute so it updates for all instances?
class Config:
debug = False
Question 23
Class attributes are useful for...
Question 24
What is the output?
class Counter:
count = 0
def __init__(self):
Counter.count += 1
c1 = Counter()
c2 = Counter()
print(Counter.count)
Question 25
What is the term for creating a specific object from a class?
Question 26
Which line correctly creates an object of class `Phone`?
Question 27
What does `isinstance(obj, MyClass)` check?
Question 28
Can you create multiple objects from a single class?
Question 29
What is the type of an object created from `class Demo:`?
class Demo:
pass
d = Demo()
print(type(d))
Question 30
What happens if you try to instantiate a class that requires arguments in `__init__` without passing them?
Question 31
What is the first parameter of every instance method in Python by convention?
Question 32
How do you call a method named `jump` on an object `player`?
Question 33
What is the output?
class Greeter:
def say_hello(self):
return "Hello!"
g = Greeter()
print(g.say_hello())
Question 34
Why do we use `self` inside methods?
Question 35
How does a method call another method within the same class?
class Math:
def double(self, x):
return x * 2
def quadruple(self, x):
return ____.double(x) * 2
