Learn JAVA MCQs

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

Which of the following is true about an interface in Java?

1) It can have default methods.

2) It can have abstract methods.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

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

1) 1

2) 2

3) 3

4) Error

Answer : 1

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

1) Integer.parseInt()

2) Integer.valueOf()

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println("Java".concat(" Programming"));?

1) JavaProgramming

2) Java Programming

3) Error

4) None of the above

Answer : Java Programming

Which of the following is true about a static method in Java?

1) It belongs to the class.

2) It can be called using the class name.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(10 & 5);?

1) 0

2) 5

3) 10

4) Error

Answer : Option 1

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

1) Classes

2) Methods

3) Both 1 and 2

4) None of the above

Answer : Classes

What is the output of System.out.println("abc".toLowerCase());?

1) abc

2) ABC

3) Error

4) None of the above

Answer : abc

Which of the following is a wrapper class in Java?

1) Integer

2) int

3) float

4) None of the above

Answer : Integer

What is the output of System.out.println(10 ^ 5);?

1) 15

2) 5

3) 12

4) Error

Answer : 15