Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java - Multiple Choice Questions (MCQ) - Introduction to Java - Set 6

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
View Answer
Correct: 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
View Answer
Correct: 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
View Answer
Correct: 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
View Answer
Correct: 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
View Answer
Correct: C



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper