• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

to Marlene

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai Marlene,
this is shyam, you have previously asnwered the question on assignment of the static variable by Karen Liu, as
_____________________________________________________________________________
Because the JLS told the compiler to do that. According to JLS 8.3.2.3,
The declaration of a member needs to appear before it is used only if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold:
1. The usage occurs in an instance (respectively static) variable initializer of C or in an instance (respectively static) initializer of C.
2. The usage is not on the left hand side of an assignment.
3. C is the innermost class or interface enclosing the usage.
A compile-time error occurs if any of the three requirements above are not met.
These restrictions are designed to catch, at compile time, circular or otherwise malformed initializations.
[ February 01, 2004: Message edited by: Marlene Miller
_________________________________________________________________________________

I have uderstood al of ur discussion, leaving an exception of point 3.
3. C is the innermost class or interface enclosing the usage.
so plz clarify it for me & what is this JLS.

thanking you
shyam
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can answer the 2nd half of your question:
The JLS is the Java Language Specification -- a very useful resource that has all the minute details of Java: how the compiler is supposed to behave, how the JRE is supposed to behave that kind of thing. Its very useful to use if you have a very specific question about something you read in here or something you read in a book.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi shyam.
Is that correct? Do I say Hi shyam, instead of Hi kumar? And do I say Hi shyam or Hi Shyam or does it matter? I am curious, which name is the patronymic name (the family name), shyam or kumar? We have to get these protocol details correct, you know, so as to show respect and not to offend out of ignorance.


The declaration of a member needs to appear before it is used only if
the member is an instance (respectively static) field of a class or interface C and
3. C is the innermost class or interface enclosing the usage.


Shyam, you did indeed read my comments Very Carefully, because you noticed that I ignored #3. #3 is about nested classes. First we try to understand the rules for top-level classes. Then (now) we try to understand the rules for nested classes.

At lines (1) and (2), there two classes enclosing the usage of a. Both A and B enclose the usage of a. B is the innermost class enclosing the usage of a.
Since the declaration of a occurs in A, but the innermost class enclosing the usage of a in (1) and (2) is B (not A), the forward-referencing restrictions do Not apply. The usage can occur before or after the declaration.
----
At lines (3) and (4), there is only one class enclosing the usage a. Class A encloses the usage of a. A is the innermost class enclosing the usage of a.
Since the declaration of a occurs in A and the class enclosing the usage of a at (3) and (4) is A, the forward-referencing restrictions Do apply. The usage Must occur after the declaration.
[ February 04, 2004: Message edited by: Marlene Miller ]
 
Sham Grandhe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi marlene,
you can call me any how since none of them are my family name, comming to the point, thank u for the kind help provided, the explanation was good but request u to give a -ve example too
hi jassic thank u for the giving me the bit of information
regards
shyam
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
shyam, do you want to see a compiler-error, when usage is in a nested class?


If all three conditions hold, the declaration must occur before the usage. Therefore, when all three conditions hold and the declaration occurs after the usage, a compiler error occurs.
If any one of the conditions does not hold, the declaraion may occur before or after the usage.
Forward Referencing Examples


[ February 05, 2004: Message edited by: Marlene Miller ]
 
Sham Grandhe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai Marlene,
this is shyam, thank u for ur kind help at once. I've gone through the snippet of code that you have sent me its real made me clearfrom all the doubts that i had, I've would like to take this leanianse to tell ur the the best in clearing doubts bye bye
thanking u shyam
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What a nice thank you, shyam. I am happy that you understand.
Thank you for letting me know that what I said made sense to you.
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic