File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Explanation

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bram Maes
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regards,
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic