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

3/6

Page

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

What will be the output for the below code?
class A{
      public void printValue(){
            System.out.println("A");
      }
}
class B extends A{
      public void printValue(){
            System.out.println("B");
      }
}

public class Test{
      public static void main(String... args){
            A b = new B();
            newValue(b);
      }
      public static void newValue(A a){
            if(a instanceof B){
                  ((B)a).printValue();
            }
      }
}

Select an option to see the answer and solution.

Determine output:
public class Test{
      static int i = 5;
      public static void main(String... args){
            System.out.println(i++);
            System.out.println(i);
            System.out.println(++i);
            System.out.println(++i+i++);
      }
}

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 var1 = 5; 
        int var2 = 6;
        int var3;
        var3 = ++ var2 * var1 / var2 + var2;
        System.out.print(var3);
    } 
}

Select an option to see the answer and solution.

Which of these are selection statements in Java?

Select an option to see the answer and solution.

On applying Left shift operator, <<, on integer bits are lost one they are shifted past which position bit?

Select an option to see the answer and solution.

With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;

Select an option to see the answer and solution.

Which of the following can be operands of arithmetic operators?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class jump_statments 
{
    public static void main(String args[]) 
    {        
         int x = 2;
         int y = 0;
         for ( ; y < 10; ++y) 
         {
             if (y % x == 0) 
                 continue;  
             else if (y == 8)
                  break;
             else
                System.out.print(y + " ");
         }
    } 
}

Select an option to see the answer and solution.

Which operator is used to invert all the digits in a binary representation of a number?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class leftshift_operator 
{
    public static void main(String args[]) 
    {        
         byte x = 64;
         int i;
         byte y; 
         i = x << 2;
         y = (byte) (x << 2)
         System.out.print(i + " " + y);
    } 
}

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 program?
class comma_operator 
{
    public static void main(String args[]) 
    {    
         int sum = 0;
         for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
             sum += i;
   System.out.println(sum);
    } 
}

Select an option to see the answer and solution.

Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration?

Select an option to see the answer and solution.

Which of these operators can skip evaluating right hand operand?

Select an option to see the answer and solution.

Which of the following is used with the switch statement?

Select an option to see the answer and solution.

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

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[])
    {
        double var1 = 1 + 5; 
        double var2 = var1 / 4;
        int var3 = 1 + 5;
        int var4 = var3 / 4;
        System.out.print(var2 + " " + var4);

    } 
}

Select an option to see the answer and solution.

What is the order of precedence (highest to lowest) of following operators?
1. &    
2. ^
3. ?:

Select an option to see the answer and solution.

What will be the output of the following Java program?
class rightshift_operator 
{
    public static void main(String args[]) 
    {    
         int x; 
         x = 10;
         x = x >> 1;
         System.out.println(x);
    } 
}

Select an option to see the answer and solution.

Which of these statements are incorrect?

Select an option to see the answer and solution.