Java Language | 10 Minute‐Test 6


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which data type value is returned by all transcendental math functions?

A.
int
B.
float
C.
double
D.
long

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

2.

What is the output of this program?

    class array_output {

        public static void main(String args[])

        {

                char array_variable [] = new char[10];

      for (int i = 0; i < 10; ++i) {

                array_variable[i] = 'i';

                System.out.print(array_variable[i] + "" );

                i++;

            } 

       }

    }

A.
i i i i i
B.
0 1 2 3 4
C.
i j k l m
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

3.

What is the output of this program?

    class evaluate {

       public static void main(String args[])

        {

            int a[] = {1,2,3,4,5};

            int d[] = a;

            int sum = 0;

            for (int j = 0; j < 3; ++j)

                sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);

            System.out.println(sum);

        }

    }

A.
38
B.
39
C.
40
D.
41

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

4.

What is the output of this program?

    class char_increment {

        public static void main(String args[])

        {

            char c1 = 'D';

            char c2 = 84;

            c2++;

            c1++;

            System.out.println(c1 + " "  + c2);

        }

    }

A.
E U
B.
U E
C.
V E
D.
U F

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Operator ++ increments the value of character by 1. c1 and c2 are given values D and 84, when we use ++ operator their values increments by 1, c1 and c2 becomes E and U respectively.

5.

What is the output of this program?

    class array_output {

        public static void main(String args[])

        {

            int array_variable [] = new int[10];

      for (int i = 0; i < 10; ++i) {

                array_variable[i] = i;

                System.out.print(array_variable[i] + " ");

                i++;

            }

        }

    }

A.
0 2 4 6 8
B.
1 3 5 7 9
C.
0 1 2 3 4 5 6 7 8 9
D.
1 2 3 4 5 6 7 8 9 10

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

When an array is declared using new operator then all of its elements are initialized to 0 automatically. for loop body is executed 5 times as whenever controls comes in the loop i value is incremented twice, first by i++ in body of loop then by ++i in increment condition of for loop.

6.

What is the output of this 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);

         }

    }

A.
1 1
B.
0 1
C.
1.5 1
D.
1.5 1.0

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

7.

What is the output of this program?

    class bitwise_operator {

        public static void main(String args[])

        {

            int var1 = 42;

            int var2 = ~var1;

            System.out.print(var1 + " " + var2);

               }

    }

A.
42 42
B.
43 43
C.
42 -43
D.
42 43

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Unary not operator, ~, inverts all of the bits of its operand. 42 in binary is 00101010 in using ~ operator on var1 and assigning it to var2 we get inverted value of 42 i:e 11010101 which is -43 in decimal.

8.

What is the output of this program?

    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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Operator > returns a boolean value. 5 is not greater than 6 therefore false is returned.

9.

What is the output of this program?

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

        }

    }

A.
10
B.
11
C.
12
D.
56

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Operator ++ has the highest precedence than / , * and +. var2 is incremented to 7 and then used in expression, var3 = 7 * 5 / 7 + 7, gives 12.

10.

What is the output of this 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);

        }

    }

A.
1
B.
2
C.
3
D.
4
Submit your test now to view the Results and Statistics with answer explanation.