• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setPriority() and labels

 
Hussain
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all ,

as i m solving sun_guoqiao mocks a very confusing quest comes
tht is:-
public class Test052
{
public static void main(String args[])
{
int i;
for( i=0; ; ++i) {
if( i > 3 ) break; //1
}
int k = 0;
labelA: { //2
if(k > 0) break labelA;
}
labelA: { //3
if(k < 0) break labelA;
}
}
}
its explanation said tht labels named can be used as long as the overlapp....
plz make me understand.wht she tried to say?
and
Other thing is :--
public class T002 extends Thread
{
public static void main(String args[])
{
T002 t = new T002();
System.out.print(t.getPriority() + " ");
t.start();
t.setPriority(1); //1
System.out.println(t.getPriority()); //2
}
}
this question explanation said tht setPriority() should be uses in order to have some effect ...
i can't undersatnd the above explanation as it also have effect of setPrioirty() before the start() method.
plz help me............
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Muhammad,
With out seeing the sentence, I can't say what someone was trying to say. I can however, explain it myself. You seem to be having an issue with the statement labels.
In java, labels are statement specific and not program specific as in C or other languages. What does that mean? Well, it means that the label is only in effect for a single statement. In the case of your example the statement is enclosed in braces:

Once I get out of the statement labelA is no longer a valid label. Therefore I can make use of the same label in another statement.
I can't re-use a valid label while it is valid (i.e., inside its' own statement). Therefore I will get a compiler error trying the following.

Regards,
Manfred.
 
Hussain
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankx sir i m gratefull to Manfred Leonhardt..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic