Learn JAVA MCQs

Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.

What is the output of System.out.println(3 ^ 2);?

1) 1

2) 3

3) 2

4) None of the above

Answer : 1

Which of the following statements is used to terminate a loop in Java?

1) exit

2) continue

3) break

4) None of the above

Answer : break

What is the output of System.out.println(7 == 7.0);?

1) true

2) false

3) Error

4) None of the above

Answer : true

Which of the following is true about the `main` method in Java?

1) It must be public.

2) It must return void.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println("1" + 1 + 1);?

1) 111

2) 3

3) Error

4) None of the above

Answer : 111

What is the output of System.out.println("Hello".substring(1, 3));?

1) He

2) Hello

3) ll

4) el

Answer : el

Which of the following statements about the Java `static` keyword is true?

1) Static methods can access instance variables.

2) Static variables are shared across all instances of a class.

3) Static methods cannot be overridden.

4) All of the above

Answer : All of the above

Which of the following is the correct way to declare a method that throws an exception?

1) public void method() throws Exception

2) public void method() throw Exception

3) void method() throws Exception

4) None of the above

Answer : public void method() throws Exception

What is the output of System.out.println(10 % 3);?

1) 3

2) 1

3) 0

4) None of the above

Answer : 1

Which of the following keywords is used to implement an interface in Java?

1) implements

2) extends

3) inherits

4) None of the above

Answer : implements