File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "forward reference doubt" Watch "forward reference doubt" New topic

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
I agree. Here's the link:
subject: forward reference doubt
It's not a secret anymore!