Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of System.out.println("abc".compareTo("abc"));?
1) 0
2) 1
3) -1
4) None of the above
Answer : Option 1
Which of the following is the correct way to declare a double variable in Java?
1) double d = 5;
2) double d = 5.0;
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
What is the output of System.out.println(1.0 / 0);?
1) Infinity
2) 0
3) Error
4) None of the above
Answer : Infinity
Which of the following is true about the `abstract` keyword?
1) It cannot be used with methods.
2) It can be used to declare a class.
3) Both 1 and 2
4) None of the above
Answer : It can be used to declare a class.
What is the output of System.out.println(5 + 2 * 3);?
1) 11
2) 16
3) 9
4) None of the above
Answer : 11
Which of the following is true about method overloading in Java?
1) It allows methods with the same name but different parameters.
2) It can change the return type.
3) Both 1 and 2
4) None of the above
Answer : It allows methods with the same name but different parameters.
What is the output of System.out.println(2.0 + 2);?
1) 4
2) 4.0
3) Error
4) None of the above
Answer : 4.0
Which of the following is used to prevent method overriding in Java?
1) final
2) static
3) private
4) None of the above
Answer : final
What is the output of System.out.println(3 * (2 + 1));?
1) 9
2) 6
3) 5
4) None of the above
Answer : 9
Which of the following is true about `super` keyword in Java?
1) It refers to the superclass.
2) It can be used to call superclass methods.
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2