Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
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.
It is sorta covered in the
JavaRanch Style Guide
subject: Instance Initializer expressions
about forward reference of variables (mock test question)
Local variables in switch statement
accessing static values
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013