Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6120155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:38:10+00:00 2026-05-23T15:38:10+00:00

Dive into Python – Guido, the original author of Python, explains method overriding this

  • 0

Dive into Python –

Guido, the original author of Python, explains method overriding this way: “Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class, may in fact end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual.)” If that doesn’t make sense to you (it confuses the hell out of me), feel free to ignore it. I just thought I’d pass it along.

I am trying to figure out an example for: a method of a base class that calls another method defined in the same base class, may in fact end up calling a method of a derived class that overrides it

class A:      
  def foo(self): print 'A.foo'      
  def bar(self): self.foo()                  

class B(A):      
  def foo(self): print 'B.foo'     

if __name__ == '__main__': 
  a = A()                
  a.bar()                   # echoes A.foo
  b = B()
  b.bar()                   # echoes B.foo

… but both of these seem kind of obvious.

am I missing something that was hinted out in the quote?


UPDATE

edited typo of calling a.foo() (instead of a.bar())and b.foo() (instead of b.bar()) in the original code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:38:10+00:00Added an answer on May 23, 2026 at 3:38 pm

    Yes, you’re missing this:

    b.bar()   # echoes B.foo
    

    B has no bar method of its own, just the one inherited from A. A‘s bar calls self.foo, but in an instance of B ends up calling B‘s foo, and not A‘s foo.

    Let’s look at your quote again:

    a method of a base class that calls
    another method defined in the same
    base class, may in fact end up calling
    a method of a derived class that
    overrides it

    To translate:

    bar (method of A, the base class)
    calls self.foo, but may in fact end up
    calling a method of the derived class
    that overrides it (B.foo that
    overrides A.foo)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read in "Dive into Python 3" that: "The readlines() method now returns an
Dive into Python - It would be tempting but incorrect to call this the
I was reading 'Dive Into Python' and in the chapter on classes it gives
I'm currently reading this amazing book called Dive into Python. Up to now everything
I'm working through 'Dive Into Python' on Google App Engine and came across this
This is a section from Dive Into Python 3 regarding strings: In Python 3,
I absolutely loved Dive Into Python when I picked up Python. In fact, tutorials
I'm currently reading Dive Into Python by Mark Pilgrim, and have gotten to the
Is there an online Java book like Dive into Python for learning Python? Other
I'm currently reading chapter 5.8 of Dive Into Python and Mark Pilgrim says: There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.