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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:31:02+00:00 2026-05-23T09:31:02+00:00

I just started BlackBerry development and I follow some of the tutorials to become

  • 0

I just started BlackBerry development and I follow some of the tutorials to become familiar with the UI objects and so on and I saw/tried this:

private MenuItem menuItemClose = new MenuItem(new StringProvider("Contacts"), 0, 0) {
    public void run() {
        onClose();
    }
};

I have not seen this way of instantiating an object before (thinking about new MenuItem), could someone explain what is happening?

And what is the difference between instantiating objects inside method definitions and in “instance variable section” like this?

  • 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-23T09:31:02+00:00Added an answer on May 23, 2026 at 9:31 am

    That’s called an “anonymous inner class.”

    Anonymous inner classes are classes which are created within another class but not named. They are instantiated by their interface or abstract base class definition and given their missing implementation inline with the instantiation.

    In this case, MenuItem is abstract – it’s missing its run() method. You’re providing the implementation of its run() method here on lines 2-4.

    Take a look at this JavaWorld article for more information about the various types and uses of inner classes.

    As for the second part of your question “what is the difference between instantiating objects inside method definitions and in “instance variable section” like this?” — the difference is scope, and when the object is instantiated.

    Non-static member variables with initial values are created when the object which contains them is instantiated. The initial value assignment (initialization) executes at that time as well.

    Static member variables with initial values are created and initialized when the class is loaded by the VM’s class loader. With eager ClassLoading, this will occur at the start of the application. With lazy ClassLoading, this will occur the first time the class is referenced by the application. I believe by default most classes that aren’t part of the Java runtime are loaded lazily.

    Both static and non-static member variables have object-level scope and are accessible by other objects according to their access modifier (public/private/protected).

    Non-static member variables are part of an object instance, and as such they are marked for garbage collection when that instance is orphaned or goes out of scope. Static member variables are only garbage collected if the class that contains them is unloaded. This only occurs if the ClassLoader instance which loaded said class is garbage collected. See this question for more info about that.

    Local variables (variables which are defined within a method) with initial values are created and initialized when that line is executed as part of normal method execution. They are marked for garbage collection (destroyed) once they go out of scope (after the method in which they’re contained finishes executing).

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

Sidebar

Related Questions

I just started with Blackberry application development. What are differences between J2ME MIDlets and
Just started doing some code porting from .Net CF to Blackberry JDE 4.6.1. But
Hi i started blackberry application development for 5.0 operating system.I just want to ask
Just started my first MVC 2.0 .net application. And I set up some default
I have just started the Hello World App using Blackberry Eclipse Plugin. I have
I have just started to learn the basics of Blackberry.... So, I am facing
Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python
Just started learning Scheme. I'm using Dr. Racket as my compiler/interpreter. I need some
This is a question-loaded post from someone who is just getting started with BB
Just started looking at some MVC JS framework / library and most of them

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.