facebook twitter pinterest google plus Youtube
www.TestsTestsTests.com
Free Online Java Tests – Branching Statements Test – Java Language Programming

Java Branching Statements Test

Free Online Java Tests
Java Language Programming

* branching statement
* branch
* break
* continue
* return

10 Question Multiple Choice Quiz with Answers and Answer Explanations

Java Branching Statements Test

1) Which of the following is one kind of a branching statement?
a) switch statement
b) break statement
c) compound statement
d) for statement

2) Which branching statement will cause a program to immediately exit a loop?
a) break
b) continue
c) return
d) All of the above

3) What will be the value returned by the method calci () if it is called with parameter”3”?

public static int calci(int n)
{
      if (n < 1)
            return 3;
      else
            return 3 + calci(n – 1);
}

a) 3
b) 6
c) 9
d) 12

4) Which of the following branching statements is most appropriate for a java method?
a) break
b) continue
c) return
d) for

5) Which of the following branching statements is used to escape current execution (iteration) and transfer control back to the start of the loop?
a) break
b) continue
c) return
d) All of the above

6) Which branching statement is used in a “switch” loop?
a) break
b) continue
c) return
d) None of the above.

7) A method in java that does not have a return value can possess any number of return statements?
a) False
b) True
c) Depends
d) Cannot be determined

8) What is the output of the program?

    class jmp_stmt {
        public static void main(String args[])
        {       
             int p = 2;
             int q = 0;
             for ( ; q < 10; ++q) {
                 if (q % p == 0)
                     continue
                 else if (q == 8)

                     break;
                else
                    System.out.print(q + ” “);
             }
        }
    }

a) 1 3 5 7
b) 2 4 6 8
c) 1 3 5 7 9
d) 1 2 3 4 5 6 7 8 9

9) What is the output of below program?

1.         class Check {
2.         public static void main(String args[])
3.         {
4.         int x =5;
5.         int y =10;
6.                      first:{
7.                         second:{
8.                            third:{
9.         if(x ==  y >>1)
break second;
}
System.out.println(x);
10.       }
System.out.println(y);
}
}
}

a) 5  10
b) 10  5
c) 5
d) 10


10) Which of the following branching statements can be both “labeled” and “unlabeled”.
a) break
b) continue
c) return
d)