Learn JAVA MCQs

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

Which of the following is used to access elements of an array in Java?

1) Index

2) Key

3) Both 1 and 2

4) None of the above

Answer : Index

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

1) Hel

2) Hello

3) lo

4) Error

Answer : Hel

Which of the following is used to implement abstraction in Java?

1) Abstract classes

2) Interfaces

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println("Java".charAt(3));?

1) a

2) J

3) v

4) Error

Answer : a

Which of the following is used to convert an integer to a string in Java?

1) Integer.toString()

2) String.valueOf()

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(15 & 7);?

1) 7

2) 15

3) 5

4) Error

Answer : 7

Which of the following is used to compare two strings in Java?

1) equals()

2) ==

3) Both 1 and 2

4) None of the above

Answer : equals()

What is the output of System.out.println("Hello".indexOf("H"));?

1) 0

2) 1

3) 2

4) Error

Answer : Option 1

Which of the following is a valid declaration of a string in Java?

1) String s = "Hello";

2) String s = new String("Hello");

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println("Java".contains("va"));?

1) true

2) false

3) Error

4) None of the above

Answer : true