Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java MCQ - Loops, Decisions and Mathematical functions - Set 21

6. Which of the following is not a valid flow control statement?
A). exit()
B). break
C). continue
D). return
View Answer
Correct: A



7.

switch(x) 
{ 
    default:  
        System.out.println("Hello"); 
}
Which two are acceptable types for x?
1. byte
2. long
3. char
4. float
5. Short
6. Long

A). 1 and 3
B). 2 and 4
C). 3 and 5
D). 4 and 6
View Answer
Correct: A



8.

public void test(int x) 
{ 
    int odd = 1; 
    if(odd)
    {
        System.out.println("odd"); 
    } 
    else 
    {
        System.out.println("even"); 
    } 
}
Which statement is true?
A). Compilation fails.
B). "odd" will always be output.
C). "even" will always be output.
D). "odd" will be output for odd values of x, and "even" for even values.
View Answer
Correct: A



9.

public class While 
{
    public void loop() 
    {
        int x= 0;
        while ( 1 ) /* Line 6 */
        {
            System.out.print("x plus one is " + (x + 1)); /* Line 8 */
        }
    }
}
Which statement is true?
A). There is a syntax error on line 1.
B). There are syntax errors on lines 1 and 6.
C). There are syntax errors on lines 1, 6, and 8.
D). There is a syntax error on line 6.
View Answer
Correct: D



10.
Determine output:

public class  Test{
        public static void  main(String args[]){
                int i;

                for (i=1;i<6;i++){
                        if(i>3) contine;
                }
        System.out.println(i);
        }
}
A). 2
B). 3
C). 4
D). 6
View Answer
Correct: D



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper