Challenge - 5 Problems
Class Syntax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple class attribute access
What is the output of this Python code?
Python
class Dog: sound = "bark" print(Dog.sound)
Attempts:
2 left
💡 Hint
Look at how class attributes are accessed directly from the class.
✗ Incorrect
The class Dog has a class attribute 'sound' set to 'bark'. Accessing Dog.sound prints 'bark'.
❓ Predict Output
intermediate2:00remaining
Output of instance method call
What is the output of this Python code?
Python
class Cat: def meow(self): return "meow" c = Cat() print(c.meow())
Attempts:
2 left
💡 Hint
Instance methods need to be called on an object instance.
✗ Incorrect
The method meow returns the string 'meow'. Calling c.meow() prints 'meow'.
❓ Predict Output
advanced2:00remaining
Output when __init__ is missing
What happens when you run this code?
Python
class Bird: def fly(self): return "flying" b = Bird() print(b.fly())
Attempts:
2 left
💡 Hint
If __init__ is missing, Python uses a default constructor.
✗ Incorrect
Python provides a default __init__ if none is defined, so b = Bird() works and b.fly() returns 'flying'.
❓ Predict Output
advanced2:00remaining
Output of class with instance variable
What is the output of this code?
Python
class Fish: def __init__(self, name): self.name = name f = Fish("Nemo") print(f.name)
Attempts:
2 left
💡 Hint
Instance variables are set inside __init__ and accessed via self.
✗ Incorrect
The instance variable 'name' is set to 'Nemo' during object creation and printed.
❓ Predict Output
expert2:00remaining
Output of class with method overriding and super()
What is the output of this code?
Python
class Animal: def speak(self): return "sound" class Dog(Animal): def speak(self): return super().speak() + " bark" d = Dog() print(d.speak())
Attempts:
2 left
💡 Hint
super() calls the parent class method inside the child method.
✗ Incorrect
Dog's speak calls Animal's speak via super(), returning 'sound', then adds ' bark'.