aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need Explanation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need Explanation" Watch "Need Explanation" New topic
Author

Need Explanation

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9618
    
    2

Hi Everyone,

I have a small doubt in the following code,




I want to know why it prints 0. On the other hand if I type int l2 = l1*this.width after the declaration of int width, it prints 100 as expected. Please anyone give me a clear cut explanation of the above code.
I appreciate your help.

Regards,
Jothi Shankar Kumar. S


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Bram Maes
Ranch Hand

Joined: Sep 27, 2006
Posts: 32
You have not intitialized width before you use it. That's why width has default 0 value. If you place int width = 10; before int ll = l * this.width; , I think it should work.


SCJP 5.0, SCEA part I
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9618
    
    2

Hi Bram Maes,

Thanks for the reply. I know that I havn't initialized width before I use it. But I want to know why when said
int ll = l * this.width;
int width = 10;

gives no error and when said
int ll = l * width; //gives error here???why???
int width = 10;

gives an error?
Please clarify this.

Regards,
Jothi Shankar Kumar. S
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023

int ll = l * width; //gives error here???why???
int width = 10;


The code breaks the forward reference rules.
What are the forward reference rules?
[ September 29, 2006: Message edited by: wise owen ]
Deyu Wang
Greenhorn

Joined: Sep 26, 2006
Posts: 6
Regards,


SCJP
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9618
    
    2

Hi Wise Owen,

Thanks for the reply. I'm getting the most of it from the link that you provided to me.

Thanks again.
Regards,
Jothi Shankar Kumar. S
Deyu Wang
Greenhorn

Joined: Sep 26, 2006
Posts: 6
int ll = l * this.width;//told the compilor the variable 'width' was defined at other place(in this class).



int ll = l * width; //illegal forward reference.

// sorry,My English is so bad.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Explanation