aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about local variables in switch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about local variables in switch " Watch "Question about local variables in switch " New topic
Author

Question about local variables in switch

Arsineh Keshishian
Greenhorn

Joined: Apr 21, 2008
Posts: 19
Hi,

When running this code:

int n = 4
final int x = 3;
final int y = 4;


I'M getting a compiler error because of j using in case y.
The compiler complains that "j may have not been initialized yet". But I can not reinitialize j either because of "duplicate local variable j".
So the only way is to make j final in case x: final int j = 0;

Why does j has to be final?

Thank you
Arsineh
Ravikanth kolli
Ranch Hand

Joined: Feb 10, 2008
Posts: 179

do you have a global variable "j"?


-kolli
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about local variables in switch