File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes explanation needed. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "explanation needed." Watch "explanation needed." New topic
Author

explanation needed.

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
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:

* The usage occurs in an instance (respectively static) variable initializer of C or in an instance (respectively static) initializer of C.
* The usage is not on the left hand side of an assignment.
* C is the innermost class or interface enclosing the usage.


can anyone explain me the last line.......does it mean

class Ankur
{
int x;
class Ankur1
{
int y=x;
}
}

is allowed ......but when it cant be allowed? what am i missing here?
Sonali Sehgal
Ranch Hand

Joined: Jul 09, 2009
Posts: 75
Hi Ankur,
Please be more specific in your question there is not interfaces in this program and no variable or class name C.Please make your question more clear.
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
but there is an inner class.....i codunt udnerstand the last point
Sonali Sehgal
Ranch Hand

Joined: Jul 09, 2009
Posts: 75


Hi Ankur ,

What I meant to say there is nothing as C in this program......


This is a program of Outer class and Inner class.In case of Inner class it can access private,protected ,default and public or any access modifier variable in inner class and declaring int y can take in that particular x variable of the outer class.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Ankur, where did you find that statement?? If we look at it in the context in which it is said, it might make sense.

Sonali, the text quoted by Ankur says C is a class/interface. So basically its just an identifier (name) for a class/interface...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
i quit.....i am unable to understand anything that is being posted today.....
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Ankur kothari wrote:i quit.....i am unable to understand anything that is being posted today.....

What did you not understand in this??
Ankit Garg wrote:Ankur, where did you find that statement??
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
nothing leave..thanks for asking
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19068
    
  40

Also, if you are going to quote the JLS, you should say so ... along with providing a note that states to which section you are quoting from.

The JLS is like legalese, to quote it out of context, is the quickest way to confuse people, or to wind up with nonsense.


All the statements are saying is that certain types of forward referencing is not allowed -- and are listed in that section of the JLS.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: explanation needed.