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

  • Home
  • SEARCH
  • 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 9074149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:34:21+00:00 2026-06-16T18:34:21+00:00

I can not figure out why this code: class HelloWorld { HelloWorld() { System.out.println(1

  • 0

I can not figure out why this code:

class HelloWorld
{
    HelloWorld()
    {
        System.out.println("1 cnstr ");
    }

    public static void main(String[] args)
    {
        HelloWorld a = new HelloWorld();
    }


    {
        System.out.println("2 cnstr ");
    }
}

gives me the output:

2 cnstr
1 cnstr

Why does line System.out.println("2 cnstr "); work? What kind of block is it? I used jdb and found that JVM starts block with this line in HelloWorld() constructor before any line in it.

Thanks for your help.

  • 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-16T18:34:22+00:00Added an answer on June 16, 2026 at 6:34 pm
    {
            System.out.println("2 cnstr ");
        }
    

    Its an Instance Initialization block. It is run before constructor of the class is executed.

    From Documentation:

    The Java compiler copies initializer blocks into every constructor.
    Therefore, this approach can be used to share a block of code between
    multiple constructors.

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

Sidebar

Related Questions

public class RunScript { public static void main(String[] args) { System.out.println(Hello World); } }
I can't figure out why this list is not displaying properly in IE7. The
Not sure why I can't figure this out. When a user makes a selection,
Not sure why I'm getting this error and can't figure it out? The cycle
I am writing some objective-C code and i can't figure out why this does
Here's my code as it stands: import static java.lang.System.*; public class Triples { private
I can not figure this out, in one of my test apps I get
I can not figure this out, I've been struggling with it for days now,
I have looked all over and cannot figure out why this code isn't working.
I cannot figure out how to convert this code from C# to VB.net. It

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.