File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Head First Android
this week in the
Instance Initializer expressions
Joined: Nov 08, 2006
Jul 07, 2007 09:44:00
I have gone through a statement saying "declare before you read".
I have the following lines of code:
int j = i;//compile time error.
int j = this.i;//compiles fine
int j = i = 20;//compiles fine.
I have the following questions:
While accessing the instance variables the compiler will append this keyword before the variable. Is my assumption correct.
Can any one explain why the compiler does not throw any error in case 3 even if we are not using this keyword before the variable?
Joined: Jul 04, 2007
Jul 08, 2007 00:36:00
I would suggest you check your code.
You cannot have repeating declarations of
within the same block.
Try keeping just one case and commenting out the others, and you will find that everything works well.
I agree. Here's the link:
subject: Instance Initializer expressions
accessing static values
Local variables in switch statement
about forward reference of variables (mock test question)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015