Object Oriented Programming - I (3140705) MCQs

MCQs of Introduction to java and elementary programming

Showing 21 to 30 out of 95 Questions
21.
What is the output of relational operators?
(a) Integer
(b) Boolean
(c) Characters
(d) Double
Answer:

Option (b)

22.
Which of these is returned by “greater than”, “less than” and “equal to” operators?
(a) Integers
(b) Floating – point numbers
(c) Boolean
(d) None of the mentioned
Answer:

Option (c)

23.
Which of the following operators can operate on a boolean variable?
   1. &&
   2. ==
   3. ?:
   4. +=
(a) 3 & 2
(b) 1 & 4
(c) 1, 2 & 4
(d) 1, 2 & 3
Answer:

Option (d)

24.
Which of these operators can skip evaluating right hand operand?
(a) !
(b) |
(c) &
(d) &&
Answer:

Option (d)

25.
Which of these statements is correct?
(a) true and false are numeric values 1 and 0
(b) true and false are numeric values 0 and 1
(c) true is any non zero value and false is 0
(d) true and false are non numeric values
Answer:

Option (d)

26.
What will be the output of the following Java code?
    class Relational_operator 
    {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            System.out.print(var1 > var2);
        } 
    }
(a) 1
(b) 0
(c) True
(d) False
Answer:

Option (d)

27.
What will be the output of the following Java code?
    class bool_operator 
    {
        public static void main(String args[]) 
        {    
             boolean a = true;
             boolean b = !true;
             boolean c = a | b;
 	     boolean d = a & b;
             boolean e = d ? b : c;
             System.out.println(d + " " + e);
        } 
    }
(a) false false
(b) true true
(c) true false
(d) false true
Answer:

Option (d)

28.
What will be the output of the following Java code?
    class ternary_operator 
    {
        public static void main(String args[]) 
        {        
             int x = 3;
             int y = ~ x;
             int z;
             z = x > y ? x : y;
             System.out.print(z);
        } 
    }
(a) 0
(b) 1
(c) 3
(d) -4
Answer:

Option (c)

29.
What will be the output of the following Java code?
    class Output 
    {
        public static void main(String args[]) 
        {    
             int x , y = 1;
             x = 10;
             if (x != 10 && x / 0 == 0)
                 System.out.println(y);
             else
                 System.out.println(++y);
        } 
    }
(a) 1
(b) 2
(c) Runtime error owing to division by zero in if condition
(d) Unpredictable behavior of program
Answer:

Option (b)

30.
What will be the output of the following Java code?
    class Output 
    {
        public static void main(String args[]) 
        {    
             boolean a = true;
             boolean b = false;
             boolean c = a ^ b;
             System.out.println(!c);
        } 
    }
(a) 0
(b) 1
(c) false
(d) true
Answer:

Option (c)

Showing 21 to 30 out of 95 Questions