• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setPriority() and labels

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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............
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankx sir i m gratefull to Manfred Leonhardt..
 
reply
    Bookmark Topic Watch Topic
  • New Topic