Bird
Raised Fist0

What is the output of this code?

medium📝 Predict Output Q4 of Q15
Python - Methods and Behavior Definition
What is the output of this code?
class Dog:
    def bark(self):
        return 'Woof!'

pet = Dog()
print(pet.bark())
AWoof!
Bbark
Cpet.bark
DError: missing argument
Step-by-Step Solution
Solution:
  1. Step 1: Understand method call on instance

    pet is an instance of Dog, calling pet.bark() runs bark method returning 'Woof!'.
  2. Step 2: Confirm print output

    print outputs the returned string 'Woof!'.
  3. Final Answer:

    Woof! -> Option A
  4. Quick Check:

    Method call output = B [OK]
Quick Trick: Method returns string printed as output [OK]
Common Mistakes:
MISTAKES
  • Expecting method name printed
  • Confusing method object with call
  • Thinking self must be passed explicitly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes