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 6183523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:22:49+00:00 2026-05-24T01:22:49+00:00

This is a follow-up from this question : Effective Java 2nd Edition, Item 17:

  • 0

This is a follow-up from this question:

Effective Java 2nd Edition, Item 17: Design and document for inheritance, or else prohibit it:

There are a few more restrictions that a class must obey to allow inheritance. Constructors must not invoke overridable methods, directly or indirectly. If you violate this rule, program failure will result. The superclass constructor runs before the subclass constructor, so the overriding method in the subclass will be invoked before the subclass constructor has run. If the overriding method depends on any initialization performed by the subclass constructor, the method will not behave as expected.

Since we are only going to touch the initialization aspect of the Java’s constructor, I assume it’s safe to compare Java’s constructor with Python’s __init__() in this question.

I am guessing since in Python I have the flexibility to decide when to call (after initializing my current class’ data attributes in this case) my ancestor’s __init__() as compared to Java where super() needs to be the first statement in a constructor’s invocation, I might be safe in calling overridden methods from __init__()?

If I am correct in guessing the aforementioned, wouldn’t I as an ancestor class designer getting left at the mercy of my subclass designer? If the subclass designer calls my __init__() before he initializes his data attributes which will be used by one of his overridden methods, and I call that method, I result in program failure!

  • 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-24T01:22:49+00:00Added an answer on May 24, 2026 at 1:22 am

    I might be safe in calling overridden methods from __init__()?

    You are. The self binding has already happened before __init__() is evaluated.

    ancestor class designer getting left at the mercy of my subclass designer?

    That’s universally true and has nothing to do with __init__() or anything else.

    Subclass developers can do anything. Also, this is Python: they have your source, and can modify that also.

    If the subclass designer calls my __init__() before he initializes his data attributes which will be used by one of his overridden methods, and I call that method, I result in program failure!

    Correct. The way this will happen is the subclass designer picked a name which you were already using. They assured that the program would fail through their choice of name.

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

Sidebar

Related Questions

This is a follow-up to my question from yesterday . I have Scott Meyers'
This question is a follow-up from How to indicate that a method was unsuccessful
This is a follow on question to How do I delete 1 file from
This follows on from this question where I was getting a few answers assuming
this kind of follows on from another question of mine. Basically, once I have
This question follows on from this vim search question I have a setting in
OK, this kind of follows on from my previous question . What I would
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
This is a follow-on question to the How do you use ssh in a
This is a follow up question to This Question . I like (and understand)

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.