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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:24:49+00:00 2026-06-05T18:24:49+00:00

Strange, but I can’t find a duplicate for this question. I have a superclass

  • 0

Strange, but I can’t find a duplicate for this question.
I have a superclass with overrideMe() method and a subclass that overrides it.
Is the final field really initialized before the subclass constructor is called?
As I can see from the output, it is.

Here’s the output:
Superclass constr
str value: someValue
Subclass constr
str value: someValue

Could you please explain this to me?
I thought that instance variables are initialized within the constructor call but not before it.

Here’s the code:

public class Test {
  public Test() {
    System.out.println("Superclass constr");
    overrideMe();
  }

  public void overrideMe() {
  }
}

class Ext extends Test {
  private final String str = "someValue";

  public Ext() {
    System.out.println("Subclass constr");
  }

  @Override
  public void overrideMe() {
    System.out.println("str value: " + str);
  }

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

EDIT:
if I declasre str field as non-final, the subclass call of it in the constructor returns null as I expect.

  • 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-05T18:24:50+00:00Added an answer on June 5, 2026 at 6:24 pm

    Yes fields are initialized before the constructor is called, and this starts with the upper class before the overloading one.

    Here’s a general presentation : http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ306_014.htm

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

Sidebar

Related Questions

This might seem like a strange question, but can I actually shut down the
Okay, so this might be kind of strange but here's the question: I have
I have a feeling this is a repost but I can't seem to find
This question might seem strange but I have been searching for an answer for
This might seam like a strange question but.... public string MyProperty { get {
This is going to seem a very strange question but im just playing about
This is a strange thing I'm doing, but how can I set the title
This code compiles but looks very strange. I have a typical and simple parent/child
Question may sounds strange but I want to make this question clear. Some people
I'm having a strange issue that I think I have a workaround for, but

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.