« Eclipse: Gracefully Loading a Heavy Plugin | Main | Asking Knowledge Questions during Job Interviews »

Jul 23, 2008

Java Riddle: Static Members in Inner Classes?

Here's something that can annoy the most experienced Java developers and is guaranteed to make people to mumble in job interviews (if that's your thing).


Consider the following piece of code:


Java Riddle

On the face of it, the two variables are identical, but of a different type. So what's the problem here? 

Hint 1: This will work with a String. It will not work with an int array.

Hint 2:  This is the error you'll be getting (at least in Eclipse):

The field OBJECT_CONST cannot be declared static; static fields can only be declared in static or top level types

This hint is only more confusing. The error seems to apply to the integer field as well. So, what's the deal here?

If you know the answer, leave a comment. 

Updated: Check out the answer here.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83548421753ef00e553b2d3918833

Listed below are links to weblogs that reference Java Riddle: Static Members in Inner Classes?:

Comments

About nWire

  • nWire Logo
    Browse & visualize all code association in one extremely powerful view, quick search for methods, fields and more. Boost your coding productivity in Eclipse™.
    Watch a 4 minute demo that will change the way you look at your code.
    Visit nwiresoftware.com

Twitter Updates

    follow me on Twitter
    My Photo

    My Other Accounts

    Delicious Digg Facebook FriendFeed Google Talk LinkedIn Reddit Twitter

    AddThis Social Bookmark Button
    Blog powered by TypePad
    Member since 05/2007