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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:15:19+00:00 2026-06-18T03:15:19+00:00

I am greatly confused with Overriding Constructors. Constructor can not be overridden is the

  • 0

I am greatly confused with Overriding Constructors. Constructor can not be overridden is the result what i get when i searched it in google my question is

public class constructorOverridden {

    public static void main(String args[]) {
        Sub sub = new Sub();
        sub.test();
    }
}

class Super {
    Super() {
        System.out.println("In Super constructor");
        test();
    }

    void test() {
        System.out.println("In Super.test()");
    }
}

class Sub extends Super {
    Sub() {
        System.out.println("In Sub constructor");
    }

    void test() { // overrides test() in Super
        System.out.println("In Sub.test()");
    }
}

when i run this i got the result as

In Super constructor
In Sub.test()
In Sub constructor
In Sub.test()

pls note the test method in subclass is executed. Is it shows that Superclass constructor is overridden. Whether is it correct ?

  • 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-06-18T03:15:20+00:00Added an answer on June 18, 2026 at 3:15 am

    Constructors aren’t polymorphic – you don’t override them at all. You create new constructors in the subclass, and each subclass constructor must chain (possibly indirectly) to a superclass constructor. If you don’t explicitly chain to a constructor, an implicit call to the parameterless superclass constructor is inserted at the start of the subclass constructor body.

    Now in terms of overriding methods – an object is of its “final type” right from the start, including when executing a superclass constructor. So if you print getClass() in the Super constructor code, you’ll still see Sub in the output. The upshot of that is the overridden method (i.e. Sub.test) is called, even though the Sub constructor hasn’t yet executed.

    This is fundamentally a bad idea, and you should almost always avoid calling potentially-overridden methods in constructors – or document very clearly that it’s going to be the case (so that the subclass code is aware that it can’t rely on variables having been initialized appropriately etc).

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

Sidebar

Related Questions

I am confused how to call a function defined in a class inside another
How can I remove spacing between the li found here? http://blog.raveis.com/badge/b.html Confused on how
This may seem silly, but I'm a bit confused about the following code: public
I am a little confused as to how to get an accurate count of
I'm new to Ruby and confused about how I can make a method in
I would greatly appreciate if you could help me with this in Java. Given
Any help here would be greatly appreciated. I have this table hospital Nurse |
I'm new to C++ programming and would greatly appreciate replies that don't assume much
I am new to writing SQL and would greatly appreciate help on this problem.
I am working on releasing an app that will greatly benefit from using the

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.