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

# Another IBM mock Exam Question

Ranch Hand
Posts: 413
• Number of slices to send:
Optional 'thank-you' note:
6)
Which of the following statements are legal?

a) int x = 5; int y = 1; x >>= y;

b) boolean x = true; boolean y = false; if (x && y){}

c) int x = 5; x + " is equal to 5;

d) int x = 5; int y = 10; x = x & y;
I would rate b as correct answer I need views from all other

Ranch Hand
Posts: 185
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by Gaurav Chikara:
6)
Which of the following statements are legal?

a) int x = 5; int y = 1; x >>= y;

b) boolean x = true; boolean y = false; if (x && y){}

c) int x = 5; x + " is equal to 5;

d) int x = 5; int y = 10; x = x & y;
I would rate b as correct answer I need views from all other

b looks good to me and it compiles and runs.

Greenhorn
Posts: 5
• Number of slices to send:
Optional 'thank-you' note:
a,b,d compiles.

Ranch Hand
Posts: 289
• Number of slices to send:
Optional 'thank-you' note:
Guarav,
To me I dont see why A and D are wrong.X>>=y is legal syntax of the form op=.This is the same as X=X>>Y.
As for D, I think X&Y will perform a logical AND on the individual bits of X and Y.That is:
X =5 = 0101;
Y=10= 1010;
X&Y = 0000 which is 0.

And I hope we notice that C is wrong only because the string is unterminated, otherwise if it was, the + operator is overloaded in Strings and that would have been a legal statement too.
Regards,
Herbert

 Don't get me started about those stupid light bulbs.