Book Image

Learning Java by Building Android Games

By : John Horton
Book Image

Learning Java by Building Android Games

By: John Horton

Overview of this book

Table of Contents (17 chapters)
Learning Java by Building Android Games
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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.