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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:44:20+00:00 2026-06-10T10:44:20+00:00

According to my understanding a default constructor initializes the state of the object to

  • 0

According to my understanding a default constructor initializes the state of the object to default values, so if i provide an explicit no-arg public constructor like this then how are the values of d and e still getting initialized to zero because in this case the default constructor is not invoked.

public class B extends A{

    private int d;
    private int e;

    public B() {
        System.out.println(d);
        System.out.println(e);
    }
}

EDIT:: The only thing default constructor does is call to super() then how come if i have a explicitly mentioned a constructor here and A has a protected variable say c which is initialized to 17 in its constructor. Should I not be explicitly calling super() to be able to see that change since I’m using my own constructor ? Why is B still getting the value of 17 through inheritance ?

  • 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-10T10:44:21+00:00Added an answer on June 10, 2026 at 10:44 am

    All class fields get assigned default values if you don’t explicitly initialize them on declaration, in a initializer block, or in your constructor. Objects get initialized to null, ints to 0, booleans to false, doubles to 0.0, float to 0.0f, long to 0L, char to ‘\u0000`…

    Please see the JLS, section 4.12.5. Initial Values of Variables as it explains it all.

    Note that these rules do not apply to variables that are local to any block or method, but instead local variables must be initialized explicitly by the coder before use.

    Edit
    Regarding your edit:

    The only thing default constructor does is call to super() then how come if i have a explicitly mentioned a constructor here and A has a protected variable say c which is initialized to 17 in its constructor. Should I not be explicitly calling super() to be able to see that change since I’m using my own constructor ? Why is B still getting the value of 17 through inheritance ?

    Answer: The super() default constructor is being called at the very beginning of B’s constructor, whether you explicitly call it or not. The only extra benefit obtained by explicitly calling the super constructor here does is to allow you to call a non-default constructor for A, if one exists, and if you so desire.

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

Sidebar

Related Questions

char imei_temp[14] = {0, }; strcpy(imei_temp, 00000000000000); According to my understanding this is valid
According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.
According to my understanding of the Apple's documentation the 'CIFaceFeature' class' object is a
If I define a class with a private default constructor and a public constructor
i'm new to c++ and having a little problem understanding about c++'s casting. According
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django
According to this post , IDEA uses Osmorc to run OSGi frameworks. It, in
According to N3290, std::unique_ptr accepts a deleter argument in its constructor. However, I can't
I have a basic plugin written according the jQuery authoring guide . This plugin
According to Apple's documentation, setAlwaysUsesMultipleValuesMarker: Sets whether the receiver always returns the multiple values

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.