Java MCQs with answers Page - 21

Here, you will find a collection of MCQ questions on Java. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 832.01K Points
Coach

Q. Find the output of the following program.

Code:
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

A

Admin • 832.01K Points
Coach

Q. 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[]

A

Admin • 832.01K Points
Coach

Q. Find the output of the following program

Code:
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

A

Admin • 832.01K Points
Coach

Q. 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

A

Admin • 832.01K Points
Coach

Q. 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}

A

Admin • 832.01K Points
Coach

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

Code:
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
  • (C) 2
  • (D) 3

A

Admin • 832.01K Points
Coach

Q. Arrays in java are

  • (A) Object references
  • (B) Objects
  • (C) Primitive data type
  • (D) None

A

Admin • 832.01K Points
Coach

Q. When is the object created with new keyword?

  • (A) At run time
  • (B) At compile time
  • (C) Depends on the code
  • (D) None

A

Admin • 832.01K Points
Coach

Q. Identify the corrected definition of a package.

  • (A) A package is a collection of editing tools
  • (B) A package is a collection of classes
  • (C) A package is a collection of classes and interfaces
  • (D) A package is a collection of interfaces

A

Admin • 832.01K Points
Coach

Q. Identify the correct restriction on static methods.

1. They must access only static data
2. They can only call other static methods.
3. They cannot refer to this or super.

  • (A) 1 and 2
  • (B) 2 and 3
  • (C) Only 3
  • (D) 1, 2 and 3

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ