What is the result?

Given:
1. class Test {
2. public static void main(String[] args) {
3. int num = 1;
4. for (num = 0; num < 3; ++num ) {
5. num *= 2;
6. }

7. System.out.println(“num = ” + (num++));
8. }
9. }
What is the result?

Given:
1. class Test {
2. public static void main(String[] args) {
3. int num = 1;
4. for (num = 0; num < 3; ++num ) {
5. num *= 2;
6. }

7. System.out.println(“num = ” + (num++));
8. }
9. }
What is the result?

A.
num = 4

B.
Compilation fails.

C.
num = 2

D.
num = 3

E.
num = 5



Leave a Reply 0

Your email address will not be published. Required fields are marked *