Vidyalelo
Java Programming · all questions

Operators
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

102

Questions

4/6

Page

Pick an option on a question to see the right answer and solution.

Which of these lines of Java code will give better performance?
1. a | 4 + c >> b & 7; 
2. (a | ((( 4 * c ) >> b ) & 7 ))

Select an option to see the answer and solution.

What will be the output of the following Java program?
class Output 
{
    public static void main(String args[]) 
    {    
         int a = 5;
         int b = 10;
         first: 
         {
            second: 
            {
               third: 
               { 
                   if (a ==  b >> 1)
                       break second;
               }
               System.out.println(a);
            }
            System.out.println(b);
         }
    } 
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
class operators 
{
    public static void main(String args[]) 
    {    
         int x = 8;
         System.out.println(++x * 3 + " " + x);
    } 
}

Select an option to see the answer and solution.

Which right shift operator preserves the sign of the value?

Select an option to see the answer and solution.

What is true about do statement?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class Output 
{
    public static void main(String args[]) 
    {    
         int a = 1;
         int b = 2;
         int c = 3;
         a |= 4;
         b >>= 1;
         c <<= 1;
         a ^= c;
         System.out.println(a + " " + b + " " + c);
    } 
}

Select an option to see the answer and solution.

Which of these is not a bitwise operator?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class increment 
{
    public static void main(String args[]) 
    {        
         int g = 3;
         System.out.print(++g * 8);
    } 
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
class Output 
{
        public static void main(String args[]) 
        {    
             int x=y=z=20;
 
        } 
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
class Output 
{
        public static void main(String args[]) 
        {    
           final int a=10,b=20;
          while(a<b)
          {
 
          System.out.println("Hello");
          }
          System.out.println("World");
 
        } 
}

Select an option to see the answer and solution.

Which of this statement is incorrect?

Select an option to see the answer and solution.

Can 8 byte long data type be automatically type cast to 4 byte float data type?

Select an option to see the answer and solution.

Which of these statements are incorrect?

Select an option to see the answer and solution.

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);
    } 
}

Select an option to see the answer and solution.

What is the value stored in x in the following lines of Java code?
int x, y, z;
 x = 0;
 y = 1;
 x = y = z = 8;

Select an option to see the answer and solution.

What will be the output of the following Java program?
class Output 
{
    public static void main(String args[]) 
    {    
         int a = 1;
         int b = 2;
         int c;
         int d;
         c = ++b;
         d = a++;
         c++;
         b++;
         ++a;
         System.out.println(a + " " + b + " " + c);
    } 
}

Select an option to see the answer and solution.

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);
    } 
}

Select an option to see the answer and solution.

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class bitwise_operator 
{
    public static void main(String args[]) 
    {    
         int a = 3;
         int b = 6;
   int c = a | b;
         int d = a & b;             
         System.out.println(c + " "  + d);
    } 
}

Select an option to see the answer and solution.

Which of the following operators can operate on a boolean variable?
1. &&
2. ==
3. ?:
4. +=

Select an option to see the answer and solution.