Learn JAVA MCQs

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

Which of the following is used to implement multiple inheritance in Java?

1) Classes

2) Interfaces

3) Both 1 and 2

4) None of the above

Answer : Interfaces

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

1) 3

2) 2

3) 1

4) None of the above

Answer : 3

Which of the following is not a valid keyword in Java?

1) native

2) synchronized

3) volatile

4) constant

Answer : constant

What is the output of System.out.println(10 >> 1);?

1) 5

2) 10

3) 20

4) None of the above

Answer : 5

Which of the following is true about abstract classes in Java?

1) They cannot be instantiated.

2) They 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(7 / 2);?

1) 3

2) 4

3) 3.5

4) None of the above

Answer : 3

Which of the following is true about the keyword `super` in Java?

1) It refers to the parent class.

2) It can be used to call parent class methods.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(Math.abs(-5));?

1) 5

2) 0

3) Error

4) None of the above

Answer : 5

Which of the following is the correct way to declare a method in Java?

1) void methodName()

2) public void methodName()

3) methodName(): void

4) None of the above

Answer : public void methodName()

What is the output of System.out.println(3 * 2 + 4);?

1) 10

2) 6

3) 7

4) None of the above

Answer : 10