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

5/6

Page

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

What will be the output of the following Java program?
class Modulus 
{
    public static void main(String args[]) 
    {    
         double a = 25.64;
         int  b = 25;
         a = a % 10;
         b = b % 10;
         System.out.println(a + " "  + b);
    } 
}

Select an option to see the answer and solution.

What should be expression1 evaluate to in using ternary operator as in this line?
expression1 ?  expression2  :  expression3

Select an option to see the answer and solution.

Modulus operator, %, can be applied to which of these?

Select an option to see the answer and solution.

Which of these is returned by "greater than", "less than" and "equal to" operators?

Select an option to see the answer and solution.

Which of the following is not a decision making statement?

Select an option to see the answer and solution.

Which of the following is not a valid jump statement?

Select an option to see the answer and solution.

What would be the output of the following code snippet if variable a=10?
if(a<=0)
{
   if(a==0)
   {
     System.out.println("1 ");
   }
   else 
   { 
      System.out.println("2 ");
   }
}
System.out.println("3 ");

Select an option to see the answer and solution.

Decrement operator, - -, decreases the value of variable by what number?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class selection_statements 
{
    public static void main(String args[])
    {
        int var1 = 5; 
        int var2 = 6;
        if ((var2 = 1) == var1)
            System.out.print(var2);
        else 
            System.out.print(++var2);
    } 
}

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,b,c,d;
             a=b=c=d=20;
            a+=b-=c*=d/=20;
           System.out.println(a+" "+b+" "+c+" "+d);
 
        } 
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of these selection statements test only for equality?

Select an option to see the answer and solution.

Which of these statements is correct?

Select an option to see the answer and solution.

What is the output of relational operators?

Select an option to see the answer and solution.

What is the valid data type for variable "a" to print "Hello World"?
switch(a)
{
   System.out.println("Hello World");
}

Select an option to see the answer and solution.

Which of the following is not a valid flow control statement?

Select an option to see the answer and solution.

The while loop repeats a set of code while the condition is not met?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is true about a break?

Select an option to see the answer and solution.

Which of these have highest precedence?

Select an option to see the answer and solution.