Object Oriented Programming - I (3140705) MCQs

MCQs of Selections , Mathematical functions and loops

Showing 1 to 10 out of 38 Questions
1.
Which of the following is used with the switch statement?
(a) Continue
(b) Exit
(c) break
(d) do
Answer:

Option (c)

2.
What is the valid data type for variable “a” to print “Hello World”?
switch(a)
{
   System.out.println("Hello World");
}
(a) int and float
(b) byte and short
(c) char and long
(d) byte and char
Answer:

Option (d)

3.
Which of the following is not a decision making statement?
(a) if
(b) if-else
(c) switch
(d) do-while
Answer:

Option (d)

4.
Which of the following is not a valid jump statement?
(a) break
(b) goto
(c) continue
(d) return
Answer:

Option (b)

5.
From where break statement causes an exit?
(a) Only from innermost loop
(b) Terminates a program
(c) Only from innermost switch
(d) From innermost loops or switches
Answer:

Option (d)

6.
Which of the following is not a valid flow control statement?
(a) exit()
(b) break
(c) continue
(d) return
Answer:

Option (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
Answer:

Option (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.
Answer:

Option (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.
Answer:

Option (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
Answer:

Option (d)

Showing 1 to 10 out of 38 Questions