Hi everyone
I have an exam coming up soon, and now is the time for review. I have some questions regarding this review, I will only ask the ones I am so unclear about.
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);
a. 0
b. 1
c. 4
d. 5
The answer is 1, b. Am i right in saying, that this loop has to be executed at least once, and when the compiler reads the "while ...." it stops? Therefore it will be executed at least once?
What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)
{
x += 10;
}
a. 90
b. 100
c. 110
d. This is an infinite loop
The answer is 100, which I do not understand why...
What is meant by the term void method?
The scope of a private instance field is
a. the instance methods of the same class
b. inside the class, but not inside any method
c. inside the parentheses of a method header
d. the method in which they are defined
The answer is a, but again, I am not sure why it is so.
When a method's return type is a class, what is actually returned to the calling
program?
a. An object of that class
b. A reference to an object of that class
c. Only the values in the object that the method accessed
d. Nothing, the return type is strictly for documentation in this situation
Last question. B is the answer. Again, need explanation.
Appreciate any help. Thanks in advance