O'Reilly logo

Android: Game Programming by Raul Portales, John Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4

Q1) What is wrong with this method?

void doSomething(){
  return 4;
}

A) It returns a value but has a void return type.

Q2) What will x be equal to at the end of this code snippet?

int x=19;
do{
  x=11;
  x++;
}while(x<20)

A) Okay, this was a slightly tricky question. Regardless of the value of x, the do block always executes at least once. Then x is set to 11, and after that, it is incremented to 12. So when the while expression is evaluated, it is true and the do block executes again. Once more, x is set to 11 and then incremented to 12. The program is stuck in a never-ending (infinite) loop. This code is most likely a bug.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required