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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:28:42+00:00 2026-05-26T02:28:42+00:00

It was difficult to search for information on this because I don’t know what

  • 0

It was difficult to search for information on this because I don’t know what it’s called, so that’s my first question I guess.

Does the use of this notation:

new Object() {//code here}

create a new object of type Object or create a new object that is a subclass of object? If it is a subclass, can you put everything you could use to declare a class (member variables, functions, inner classes), inside the braces? Could you even write a constructor for it?

  • 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-26T02:28:43+00:00Added an answer on May 26, 2026 at 2:28 am

    This is called an anonymous class. Basically, you’re defining a subclass in-place.

    This call:

    Object a = new Object() {
       // stuff
    };
    

    .. defines a new subclass of Object with //stuff in it (just like declaring that in a normal A extends Object.

    Wikipedia has a good article about them too.

    They’re useful primarily for closures, which means that the functions defined in your anonymous class have access to final variables from the enclosing scope.

    Example-ish:

    interface Function {
        void run();
    }
    
    static void example(Function f) {
        f.run();
    }
    
    void runExample() {
        final int a = 10;
        example(new Function() {
            void run() {
                // Notice that "a" was defined in the outer scope
                System.out.println(a);
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't think this is a repost, difficult to search for the word between because
This seems like a simple question, but it is difficult to search for. I
This is a difficult and open-ended question I know, but I thought I'd throw
This is a difficult question to search in Google since it has other meaning
I am working on building my first search-engine friendly CMS. I know that perhaps
I'm sorry if this was already answered, but it's kind of difficult to search
difficult to look this up if it has been asked previously since I don't
I have a particularly difficult form that I am trying to click the search
We're currently using Lucene 2.1.0 for our site search and we've hit a difficult
I am having some difficulty writing a function that will search through a directory

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.