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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:51:13+00:00 2026-06-10T06:51:13+00:00

While going through one of the library, I found the following construct in java

  • 0

While going through one of the library, I found the following construct in java which is really new for me. Assume there is a class Point in java.

class Point {
    int x;
    int y;
    public Point() {}
    public Point(int x, int y) {
    this.x = x;
    this.y = y;
    }
}

While creating instance for Point, they initialize the variables x and y in the instance creation itself as below :

Point inst = new Point() {
            {
                this.x = 10;
                this.y = 20;
            }
        };

Is this related to instance block in java or something different?

  • 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-10T06:51:14+00:00Added an answer on June 10, 2026 at 6:51 am

    Your second example:

    1. creates an anonymous class derived from Point
    2. uses an initializer block to intialise values

    The syntax:

    new Object() { ... }
    

    looks like an Object, but is in fact creating a new object derived from Object. The inner braces then declare the initialiser block.

    It’s a practise occassionally used to initialise collections e.g.

    new ArrayList<String>(){{
       add("1");
       add("2");
    }};
    

    etc. One thing to note is that it’s an inner class and consequently there’s an implict reference to the outer (surrounding) class. Not normally a problem unless (say) you come to serialise this.

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

Sidebar

Related Questions

While going through a WP7.5 background transfer service policy, one can read the following:
While going through Effective C++ (by Scott Meyers), I came across the following code
While going through the syslog file, I found a message like shutdown via gdm
Yesterday while going through this question, I found a curious case of passing and
While going through one project, I have seen that the memory data is 8
While I was going through the architecture of TMS320F2806x (Piccolo) MCUs, I have found
I'm going through an online lesson , which usually has a very simple one
While going through one of the problems in Python Challenge , I am trying
While going through one of our own projects, that other developer used rand() to
I am very new to iPhone dev and while going through Sams Teach Yourself

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.