• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock

 
Shalini Srivastav
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it wont compile as there is a JILL label which has no meaning.

I don't know how it is valid in mock question ?
untitled.JPG
[Thumbnail for untitled.JPG]
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shalini Srivastav wrote:I thought it wont compile as there is a JILL label which has no meaning.

I don't know how it is valid in mock question ?


First of all, please UseAMeaningfulSubjectLine.

Label is always attached with a statement. So, when you are trying to use "uselesslabel:" a label without a statement, it will give you errors...
 
Shalini Srivastav
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not correct.
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shalini Srivastav wrote:You are not correct.

You got an error??? Or What are you trying to say?
 
Shalini Srivastav
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what did you mean by statement.

 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A statement in Java forms a complete command to be executed and can include one or more expressions.
or
A statement is a single "command" that is executed by the Java interpreter.

Different kinds of statements in java for example:
1). Declaration Statement (e.g. int value;)
2). Expression Statement (e.g. value=7;)
3). Control flow Statement (e.g. for(int i=0; i<10;i++) {} )
4). Null Statement (e.g. ; )
 
Kedar Pethe
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shalini Srivastav wrote:I thought it wont compile as there is a JILL label which has no meaning.

I don't know how it is valid in mock question ?


Add a semicolon(;) at the end of uselsesslabel: (ie- uselsesslabel:;)

Just by luck it compiles without errors... could somebody explain this???
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am surprised how a topic which is not used at all in the Java world could ignite such a discussion. In OCPJP, labels are there only for the questions with labelled break. Application wise, labels are never used at all. This is a migration from C's jump statements.

Also Shalini, Gaurang's code is correct


This code runs and outputs the String inside the println.

The error is due to improper ending(without the semicolon) which actually makes the the closing bracket as a statement which is clearly an error and this is stated very specifically when you do a javac on the class file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic