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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:01:53+00:00 2026-05-25T19:01:53+00:00

Many articles say objects get created only after the class’s constructor gets called. But

  • 0

Many articles say objects get created only after the class’s constructor gets called. But I found this snippet and it works fine.

public class A {

    public A(){
        this.foo();//line #1
    }

    private void foo() {
        System.out.print("without an instance..!!!!");

    }
}

class B extends A
{
    public static void main(String[] args){

    A a = new A();  //line #2
    }
    }

Here you see, I’m trying to create an object of its super class in line #2 and in its constructor how come its method got called without an instance. What’s going on here, is Constructer of instance of A is getting called here.?

  • 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-25T19:01:54+00:00Added an answer on May 25, 2026 at 7:01 pm

    The constructor is always called when an object is created. Even if you don’t explicitly define a constructor, the compiler will generate one for you with an empty body.

    You may call other methods of the class from the constructor. All non-static methods get an implicit (compiler generated) parameter to this, the actual class instance. However, it is important to know that while executing the constructor, the object is not yet fully created, although all data members of the class in question (if there are such) have already been initialized, at least to some default value. Because of this, you

    • should not publish this (i.e. pass it to other objects / threads) before exiting the constructor call, and
    • you should not call non-final, non-private methods from the constructor.

    Doing either of these (in a non-final class) means that you give access to an object not yet fully constructed, which may result in subtle, hard to find bugs later. E.g. if the virtual method in question is overridden in a subclass and the implementation depends on some member defined and initialized only in the subclass constructor, the method gets called before the subclass member is correctly initialized, thus it won’t have the value you would expect.

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

Sidebar

Related Questions

when i search for adding a system call, i get many articles but they
Let's say I have two objects: Articles and Categories with a many-many relationship between
I have seen many articles and Questions/Answers Regarding Lock Escalation but following things are
I've seen many many articles on how to read XML into a JTree but
I've read so many articles, but none seem to answer this question. Or maybe
i have read many articles that can be found on soap , i am
I read many articles and all says Java is pass by value. But i
There are many articles that described how to create a custom shaped window in
I tried to read many articles on dofactory , wikipedia and many sites. I
An article has many articles that it refers to and many other articles can

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.