Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is true about the String class in Java?
1) It is mutable.
2) It is immutable.
3) It cannot be modified after creation.
4) Both 2 and 3
Answer : Both 2 and 3
Which of the following is not a valid method in the Math class?
1) abs()
2) sqrt()
3) round()
4) random()
Answer : random()
What is the default value of an int in Java?
1) 0
2) 1
3) null
4) undefined
Answer : Option 1
Which of the following is used to terminate a loop in Java?
1) break
2) exit
3) return
4) continue
Answer : break
Which of the following is true about constructors in Java?
1) A constructor must have a return type.
2) A constructor can be static.
3) A constructor is called automatically when an object is created.
4) None of the above
Answer : A constructor is called automatically when an object is created.
Which of the following is used to check if two objects are equal in Java?
1) ==
2) equals()
3) compareTo()
4) None of the above
Answer : equals()
What is the output of System.out.println(10 / 0);?
1) Infinity
2) NaN
3) Exception
4) None of the above
Answer : Exception
Which of the following is used to compare two strings in Java?
1) ==
2) equals()
3) compareTo()
4) Both 2 and 3
Answer : Both 2 and 3
Which of the following is not a valid keyword in Java?
1) this
2) super
3) finalize
4) None of the above
Answer : finalize
Which of the following is true about exceptions in Java?
1) They can be checked or unchecked.
2) They must be caught or thrown.
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2