aspose file tools*
The moose likes Beginning Java and the fly likes Instance Initializer expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Instance Initializer expressions" Watch "Instance Initializer expressions" New topic
Author

Instance Initializer expressions

Ravindranath Chowdary
Ranch Hand

Joined: Nov 08, 2006
Posts: 71
Hi Friends,
I have gone through a statement saying "declare before you read".

I have the following lines of code:

case 1:
int j = i;//compile time error.
int i;

case 2:
int j = this.i;//compiles fine
int i;

case 3:
int j = i = 20;//compiles fine.
int i;

I have the following questions:
Q 1:
While accessing the instance variables the compiler will append this keyword before the variable. Is my assumption correct.

Q 2:
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?

Thanks,
Ravindra.
Michael Jennings
Greenhorn

Joined: Jul 04, 2007
Posts: 20
I would suggest you check your code.

You cannot have repeating declarations of i and j 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: http://aspose.com/file-tools
 
subject: Instance Initializer expressions