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

  • Home
  • SEARCH
  • 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 6732759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:41:18+00:00 2026-05-26T10:41:18+00:00

In superclass in Python , how can I call the function that’s overridden in

  • 0

In superclass in Python, how can I call the function that’s overridden in its subclass?

class A:
    @staticmethod
    def interfaceBasedMethod():
        print "Want to delegate to overriding method in subclass"

    @staticmethod
    def a():
        interfaceBasedMethod() # <-- I know this causes error. But here 
                               # I want to call the overridden method in subclass.

class B(A):
    @staticmethod
    def interfaceBasedMethod():
        print "Class B processes."

if __name__ == "__main__":
    b=B
    b.a()

Ideal output:

Class B processes.

Google search doesn’t really return pages about Interface-Based Programming in Python, although it should be common in Java etc. Thanks!

  • 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-26T10:41:18+00:00Added an answer on May 26, 2026 at 10:41 am

    Putting aside questions of style, use classmethod not staticmethod. It passes in the class which is being used.

    class A:
        @classmethod
        def interfaceBasedMethod(cls):
            print "Want to delegate to overriding method in subclass"
    
        @classmethod
        def a(cls):
            cls.interfaceBasedMethod()
    
    class B(A):
        @classmethod
        def interfaceBasedMethod(cls):
            print "Class B processes."
    
    if __name__ == "__main__":
        b=B
        b.a()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python, consider I have the following code: class SuperClass(object): def __init__(self, x): self.x
I noticed that when you call a superclass's methods, you need to do something
I have an AbstractEntity class as superclass for all my entites that defines an
How do I stop a function/procedure in a superclass from been overridden in a
I have some python module, which has a class ModuleClass and I can't modify
In Python, the object class serves as the root superclass for all the (new-style)
I have a python class hierarchy, that I want to extend at runtime. Furthermore
A subclass needs to know when particular events occur withing its superclass, but there
I have an abstract superclass and various subclasses. Each subclass contains a value that
Why can't I use super to get a method of a class's superclass? Example:

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.