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 = 2

B.
num = 4

C.
num = 3

D.
num = 5

E.
Compilation fails.



Leave a Reply 0

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