Quiz Discussion

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

 

Course Name: Java

  • 1]

    0

  • 2]

    1

  • 3]

    3

  • 4]

    -4

Solution
No Solution Present Yet

Top 5 Similar Quiz - Based On AI&ML

Quiz Recommendation System API Link - https://fresherbell-quiz-api.herokuapp.com/fresherbell_quiz_api

# Quiz
1
Discuss

Which of these statements are incorrect?

  • 1]

    Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms

  • 2]

    Assignment operators run faster than their equivalent long forms

  • 3]

    Assignment operators can be used only with numeric and character data type

  • 4]

    None of the mentioned

Solution
2
Discuss

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

  • 1]

    Integers

  • 2]

    Floating – point numbers

  • 3]

    Boolean

  • 4]

    None of the mentioned

Solution
3
Discuss

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

 

  • 1]

    compile time error

  • 2]

    runtime error

  • 3]

    a=20 b=0 c=20 d=1

  • 4]

    none of the mentioned

Solution
4
Discuss

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

 

  • 1]

    0 64

  • 2]

    64 0

  • 3]

    0 256

  • 4]

    256 0

Solution
5
Discuss

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

 

  • 1]

    7 2

  • 2]

    7 7

  • 3]

    7 5

  • 4]

    5 2

Solution
6
Discuss

 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;
  • 1]

    0

  • 2]

    1

  • 3]

    9

  • 4]

    8

Solution
7
Discuss

Which of these lines of Java code will give better performance?

   1. a | 4 + c >> b & 7; 
   2. (a | ((( 4 * c ) >> b ) & 7 ))
  • 1]

    1 will give better performance as it has no parentheses

  • 2]

    2 will give better performance as it has parentheses

  • 3]

    Both 1 & 2 will give equal performance

  • 4]

    Dependent on the computer system

Solution
8
Discuss

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

 expression1 ?  expression2  :  expression3
  • 1]

    Integer

  • 2]

    Floating – point numbers

  • 3]

    Boolean

  • 4]

    None of the mentioned

Solution
9
Discuss

Which of these statements are incorrect?

  • 1]

    The left shift operator, <<, shifts all of the bits in a value to the left specified number of times

  • 2]

    The right shift operator, >>, shifts all of the bits in a value to the right specified number of time

  • 3]

    The left shift operator can be used as an alternative to multiplying by 2

  • 4]

    The right shift operator automatically fills the higher order bits with 0

Solution
10
Discuss

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

 

  • 1]

    1

  • 2]

    2

  • 3]

    Runtime error owing to division by zero in if condition

  • 4]

    Unpredictable behavior of program

Solution
# Quiz