Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Non access modifiers for Inner class variables

 
Thread Tools Search this Thread
Old 02-23-2004, 06:26 PM   #1
Default Non access modifiers for Inner class variables


I am preparing for my scjp exam, and cud not find specific answer to
my question that why Inner Classes cannot declare static variables. If
anyone cud provide some info on this, it'wud be very helpful.

thanks in advance


shila
  Reply With Quote
Old 02-24-2004, 01:47 AM   #2
hiwa
 
Posts: n/a
Default Re: Non access modifiers for Inner class variables

(shila) wrote in message news:<. com>...
> I am preparing for my scjp exam, and cud not find specific answer to
> my question that why Inner Classes cannot declare static variables. If
> anyone cud provide some info on this, it'wud be very helpful.
>
> thanks in advance

Inner class is a non-static nested class inside another class. That
means its existence depends on enclosing class's instance/object. In
other words, they can not have their own independent existence as a
sovereign class ... if enclosing class object is not created, inner
class can't have its existence, so they can't have static members.
Only an independent sovereign class can have its own static members.
  Reply With Quote
Old 02-24-2004, 01:39 PM   #3
John C. Bollinger
 
Posts: n/a
Default Re: Non access modifiers for Inner class variables

hiwa wrote:
> (shila) wrote in message news:<. com>...
>
>>I am preparing for my scjp exam, and cud not find specific answer to
>>my question that why Inner Classes cannot declare static variables. If
>>anyone cud provide some info on this, it'wud be very helpful.
>>
>>thanks in advance

>
> Inner class is a non-static nested class inside another class. That
> means its existence depends on enclosing class's instance/object. In
> other words, they can not have their own independent existence as a
> sovereign class ... if enclosing class object is not created, inner
> class can't have its existence, so they can't have static members.
> Only an independent sovereign class can have its own static members.


And although the stated facts are all true, they do not constitute an
insurmountable problem. The fundamental answer is that Sun decided to
place the restriction for reasons of their own, even though the virtual
machine specification is not incompatible with inner classes having
static members. I don't work for Sun and never have, so I can only
speculate as to Sun's reasons, but I would place my bets in two areas:

(1) A philosophical objection based on arguments similar to those hiwa
gave above, and

(2) Reserving the possibility of a future JVM revision that may be
facilitated by the restriction.


John Bollinger


  Reply With Quote
Old 02-24-2004, 05:06 PM   #4
Tor Iver Wilhelmsen
 
Posts: n/a
Default Re: Non access modifiers for Inner class variables

"John C. Bollinger" <> writes:

> even though the
> virtual machine specification is not incompatible with inner classes
> having static members.


Mostly because nested classes are synthesized into top-level classes
with compiler-enforced restrictions on use.

> (2) Reserving the possibility of a future JVM revision that may be
> facilitated by the restriction.


.... like turning anonymous inner classes into proper lambda
expressions or Smalltalk-like blocks.

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump