Java Coding MCQs with answers Page - 1

You will find multiple-choice questions (MCQs) related to #Java Coding here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 828.03K Points
Coach

Q. Determine output:

Code:
class A{
        public static void main(String args[]){
	        int x;
 	        x = 10;
	        if(x == 10){
		        int y = 20;
		        System.out.print("x and y: "+ x + " " + y);
		        y = x*2;
	        }
	        y = 100;
	        System.out.print("x and y: " + x + " " + y);
        }
}
  • (A) 10 20 10 100
  • (B) 10 20 10 20
  • (C) 10 20 10 10
  • (D) Error

A

Admin • 828.03K Points
Coach

Q. What is the purpose of this bit of code?~~~void init()~~~{~~~}

  • (A) A class that initializes the applet.
  • (B) A required method in an applet.
  • (C) A place to declare variables.
  • (D) Interacting with the user.

A

Admin • 828.03K Points
Coach

Q. Will this Java program generate same output is executed again?
class Output
{
public static void main(String args[])
{
int y = double z = Math.random();
System.out.print(y);
}
}

  • (A) Yes
  • (B) No
  • (C) Compiler Dependent
  • (D) Operating System Dependent

A

Admin • 828.03K Points
Coach

Q. Consider the following list. int[] intList = {35, 12, 27, 18, 45, 16, 38}; What is the minimum number of comparisons that have to be made to find 18 using a sequential search on intList?

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4

A

Admin • 828.03K Points
Coach

Q. What will be the output of the following Java code snippet?
enum Levels
{
private TOP,

public MEDIUM,

protected BOTTOM;
}

  • (A) Runtime Error
  • (B) EnumNotDefined Exception
  • (C) It runs successfully
  • (D) Compilation Error

A

Admin • 828.03K Points
Coach

Q. What is the output of the Java code snippet?

Code:
int a=10, b=5, c=3;
int d = a+c/2*b;
System.out.println(d);
  • (A) 17.5
  • (B) 32.5
  • (C) 15
  • (D) 30
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More