wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Declaration cannot be labelled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Declaration cannot be labelled" Watch "Declaration cannot be labelled" New topic
Author

Declaration cannot be labelled

Sridevi Shrikanth
Ranch Hand

Joined: Jan 11, 2001
Posts: 31
Hi,
In the potential traps as given by Ajith, one of the traps says
Declaration cannot be labelled.

However the following code runs perfectly well.
public class Decl
{

private static void main(String[] args)
{
label1: float f = 1.3f;
label2 : for(int i=0;i<10;i++)
{
System.out.println(i);
}

}
}
Could anyone explain to me the context in which it is invalid.
Any explanation is truly appreciated.
Thank you.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I believe you can label anything in your program, but you can't use a break or continue with a label unless what immediatly follows the label is a loop for continue and break or a switch statement for break only (not continue).
Bill
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Sridevi, which compiler are you using? I cannot compile your program ( Suns' javac ( JDK1.3 ) compiler ). I get an error, as expected, that says " A declaration cannot be labeled" indicating the label1: float f = 1.3f ; statement.

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Sridevi Shrikanth
Ranch Hand

Joined: Jan 11, 2001
Posts: 31
JDK 1.1.7. Probably thats why I get the error.
Thank you.
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Sirdevi,
I think declarations cannot be labeled.
Btw, can anyone tell me where the traps as listed by ajith or somebody else is in the web.
TIA.

Sun Certified Programmer for Java 2 Platform
Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
I have the list of the potential SCJP traps in my study notes.
You can download it at http://www.geocities.com/velmurugan_p/

------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/


------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Declaration cannot be labelled
 
Similar Threads
Cleared SCJP 5 with 78%
Khalid's Mock Test.
Why a declaration cannot be labelled
labeled break and continue
break and continue in the SCJA exam?