• 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

Another IBM mock Exam Question

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
experts who read it
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
experts who read it


b looks good to me and it compiles and runs.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a,b,d compiles.
 
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic