Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of System.out.println(5 == 5.0);?
1) true
2) false
3) Error
4) None of the above
Answer : true
Which of the following is not a valid package in Java?
1) java.util
2) java.lang
3) java.io
4) java.net.core
Answer : java.net.core
Which of the following is used to check if a string contains a substring in Java?
1) contains()
2) has()
3) indexOf()
4) None of the above
Answer : contains()
What is the output of System.out.println(Math.round(2.5));?
1) 2
2) 3
3) 2.5
4) None of the above
Answer : 3
Which of the following is true about method overloading in Java?
1) Methods must have different return types.
2) Methods must have different parameter lists.
3) Both 1 and 2
4) None of the above
Answer : Methods must have different parameter lists.
Which of the following is used to stop a thread in Java?
1) stop()
2) interrupt()
3) terminate()
4) None of the above
Answer : interrupt()
What is the output of System.out.println(10 != 10);?
1) true
2) false
3) Error
4) None of the above
Answer : false
Which of the following is true about the main() method in Java?
1) It must be static.
2) It must have a return type of void.
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
Which of the following is not a valid exception in Java?
1) ArithmeticException
2) NullPointerException
3) ArrayIndexOutOfBoundsException
4) ClassNotFound
Answer : ClassNotFound
Which of the following is true about the finalize() method in Java?
1) It is used for cleanup before an object is garbage collected.
2) It can be called explicitly.
3) Both 1 and 2
4) None of the above
Answer : It is used for cleanup before an object is garbage collected.