Remix education
study materialTopic wise MCQs

Top 30 incredible java mcq questions and answers

Simple Questions For java mcq questions and answers

Solve These Questions And Check Your Knowladge :

Number of primitive data types in Java are?

(A) 6

(B) 7

(C) 8

(D) 9

Answer :

There are 8 types of primitive data types- int, char, boolean, byte, long, float, short, double.

What is the size of float and double in java?

(A) 32 and 64

(B) 32 and 32

(C) 64 and 64

(D) 64 and 32

Answer :

The size of float and double in java is 32 and 64.

Automatic type conversion is possible in which of the possible cases?

(A) Byte to int

(B) Int to long

(C) Long to int

(D) Short to int

Answer :

Automatic type conversion is possible in Int to long.

Find the output of the following code.


    int Integer = 24;
    char String  = ‘I’;
    System.out.print(Integer);
    System.out.print(String);

(A) Compile error

(B) Throws exception

(C) I

(D) 24 I

Answer :

24 I will be printed.

Find the output of the following program.


    public class Solution{
public static void main(String[] args){
             short x = 10;
             x =  x * 5;
             System.out.print(x);
}
}

(A) 50

(B) 10

(C) Compile error

(D) Exception

Answer :

This will give compile error – “Lossy conversion from int to short”

Find the output of the following program.


public class Solution{
public static void main(String[] args){
             byte x = 127;
             x++;
             x++;
             System.out.print(x);
}
}

(A) -127

(B) 127

(C) 129

(D) 2

Answer :

Range of byte data in java is -128 to 127. But the byte data type in java is cyclic in nature.

Select the valid statement.

(A) char[] ch = new char(5)

(B) char[] ch = new char[5]

(C) char[] ch = new char()

(D) char[] ch = new char[]

Answer :

char[] ch = new char[5] is the correct syntax for declaring a character array.

Find the output of the following program.

public class Solution{
public static void main(String[] args){
       int[]  x = {120, 200, 016};
       for(int i = 0; i < x.length; i++){
                System.out.print(x[i] + “ “);
       }                   
}
}

(A) 120 200 016

(B) 120 200 14

(C) 120 200 16

(D) None

Answer :

016 is an octal number, its equivalent decimal number is 14. Hence answer is B.

When an array is passed to a method, what does the method receive?

(A) The reference of the array

(B) A copy of the array

(C) Length of the array

(D) Copy of first element

Answer :

When an array is passed to a method, a reference of the array is received by the method.

Read More : Top 30 incredible java mcq questions and answers

Select the valid statement to declare and initialize an array.

(A) int[] A = {}

(B) int[] A = {1, 2, 3}

(C) int[] A = (1, 2, 3)

(D) int[][] A = {1,2,3}

Answer :

int[] A = {1, 2, 3} is the valid way of declaring arrays.

Find the value of A[1] after execution of the following program.

int[] A = {0,2,4,1,3};
for(int i = 0; i > a.length; i++){
a[i] = a[(a[i] + 3) % a.length];
}

(A) 0

(B) 1

Remix education

(C) 2

(D) 3

Answer :

a.length = 5
A[0] = a[(0 + 3) % 5] = a[3] = 1
So, a[0] =  a[3] = 1
A[1] = a[(2 + 3) % 5] = a[0] = 1
Therefore, a[1] = 1;

Arrays in java are-

(A)Object references

(B) objects

(C) Primitive data type

(D) None

Answer :

Arrays are objects in java. It is a container that holds a fixed number of items of a single type.

When is the object created with new keyword?

(A) At run time

(B) At compile time

(C) Depends on the code

(D) None

Answer :

The object created with new keyword during run-time.

Remix education

For Full Mcqs : Click Here