aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes forward reference doubt 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 "forward reference doubt" Watch "forward reference doubt" New topic
Author

forward reference doubt

shreya prabhu
Ranch Hand

Joined: Feb 10, 2007
Posts: 31
public class NonStaticInitializers {
int length=10;
double area=length*width;//illegal
//double area=length*this.width;//legal
int width=10;
int sqside=height=20;//legal
int height;
}
i am not able to understand this code` .can anybody please explain it to me?what makes this.width legal?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
It is not considered a forward reference if you say this.weight because you're not accessing the variable through its simple name.
Priya Viswam
Ranch Hand

Joined: Dec 28, 2006
Posts: 81

int sqside=height=20;//legal


The forward referencing rule says that you cannot use a
variable on the right hand side of an assignment statement
or use it to print something before it can be declared.

since height is on the left hand side, it wont create any problem.


SCJP 1.5<br />SCWCD 1.4
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: forward reference doubt