File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Acessing local variable..ple help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Acessing local variable..ple help" Watch "Acessing local variable..ple help" New topic

Acessing local variable..ple help

Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
I have the following code, can you please help me to figure out how I could access the f_seat_status variable outside the if loop? Thank you.
int l_session_seats_available =3;
if (l_session_seats_available > 0) {
String f_seat_status = "enrolled";
} else if (l_session_seats_available <= 0) {
String f_seat_status = "waiting list";
<%=f_seat_status %> <--- How do I get the f_seat_status outside the IF loop??
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
You can't. The scope of the variable is visible only in the block you declared it. Why don't you declare it outside?

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Malhar Barai
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
You can write the code in the following way

Just declare outside the scope.

Malhar Barai
SOA & Java Book
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Despite the fact that this appears within a JSP, it's really a basic Java question, so I'm going to move this off to Java in General (beginner).
[ October 21, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Acessing local variable..ple help
It's not a secret anymore!